Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Is Fruit Function Flawed?
00:00
5 left

Is Fruit Function Flawed?

MediumPython

Problem

Given a Python function def is_fruit(item): return item in fruits where fruits is a Python list, is there a design issue?

Asked in the CoderPad Online Assessment stage. Implement the corrected design for repeated membership checks.

Input and Output

Implement fruit_membership(fruits, items). fruits is a list of strings representing known fruits, and items is a list of strings to check. Return a list of booleans in the same order as items.

Constraints

  • 0 <= len(fruits), len(items) <= 10^5
  • Each input value is a string
  • Duplicate values may appear in fruits
  • Return results in the same order as items

Function Signature

def fruit_membership(fruits, items):
Interviewer

Your question is Is Fruit Function Flawed?. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.