Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Duplicate Detection in List

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Duplicate Detection in List. Start with the requirements on the right.

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.

Problem

Uber Eats can receive a list of item identifiers from a cart or order request. Implement a function that returns True if a specific target item appears more than once in the list, and False otherwise.

Formal Specification

  • Input: items, a list of values, and target, the value to search for.
  • Output: A boolean indicating whether target occurs at least two times in items.
  • Treat values as equal according to Python's standard equality rules.
  • Return as soon as two matching occurrences are found.

Examples

Example 1

Input: items = ["burger", "fries", "burger"], target = "burger"
Output: True

The target appears at indices 0 and 2.

Example 2

Input: items = ["coffee", "tea", "juice"], target = "tea"
Output: False

The target appears only once.

Example 3

Input: items = ["salad", "salad", "salad"], target = "salad"
Output: True

Two matching occurrences are enough, so the function can stop early.

Constraints

  • 0 <= len(items) <= 10^5
  • Each list value and target is a hashable Python value.
  • The target may be absent from the list.
  • The list may contain duplicate values unrelated to target.

Constraints

  • 0 <= len(items) <= 10^5
  • Each list value and target is hashable
  • The target may be absent from the list
  • The target may occur more than twice

Function Signature

def appears_more_than_once(items, target):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output