Coding · should-tier · asked at Amazon, Apple, Google, Meta, Microsoft, Netflix
Contains Duplicate
Problem
You are given an array of integers nums. Decide whether any value occurs more than once. Return True if some value appears at least twice, otherwise return False.
- The array is non-empty and has at most 200,000 elements.
- Each value fits comfortably in a 64-bit integer; magnitudes up to a billion are possible.
Examples
nums = [4, 9, 2, 9, 5]→True, because9appears at indices 1 and 3.nums = [12, -3, 0, 7]→False, every value is distinct.nums = [42]→False, a single element cannot repeat.
Hints
- The question is only "have I seen this value before?" for each element in turn.
- Sorting would put equal values next to each other, but is there something faster than O(n log n)?
- Walk the array once while inserting into a hash set; the first value already present is your answer.
Last reviewed 8 September 2026
Locked
Approach · Solution (Python) · Complexity · Follow-ups · Company variations · Tests
The rest of this question — the worked approach, the Python solution with passing tests, complexity, follow-ups and how each company frames it — is part of the guides.
Get the full guide
Pick the company you're interviewing with. Each guide has every question tiered for that loop — one-time purchase, lifetime access.
Secure payment by Stripe · instant access · refund questions: [email protected]
Also in: Apple, Google, Meta, Microsoft, Netflix
Interviewing at more than one? All 6 guides for $499 · save $395
Not ready to buy? Get the free starter pack — 13 questions with full solutions.