Contains Duplicate II
A easy-tier problem at 49% community acceptance, tagged with Array, Hash Table, Sliding Window. Reported in interviews at Palantir Technologies and 8 others.
Contains Duplicate II hits your OA from Airbnb, Google, Meta, Netflix, and Microsoft. It's labeled easy, but the acceptance rate sits at 49%, meaning half the candidates who submit fail it. The trap isn't the algorithm, it's misreading the constraint. You need to find if two identical values exist within a window of size k in an array. Most people either brute force it or miss the sliding window entirely. If you hit this live and blank on the pattern, StealthCoder surfaces a working solution in seconds, invisible to the proctor.
Companies that ask "Contains Duplicate II"
Contains Duplicate II is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.
Get StealthCoderThe problem asks for duplicates with an index distance constraint, not just any duplicates. The naive approach checks every pair, O(n2), which times out. The correct move is a sliding window with a hash set. Keep a set of at most k elements. Slide right, adding new elements and removing old ones when the window exceeds size k. If you ever see a duplicate inside the window, return true immediately. Common miss: candidates treat this as a simple 'find any duplicate' problem and ignore k, then fail the test cases that prove the index constraint matters. Another pitfall: using a hash table to store indices when a set suffices and runs faster. StealthCoder handles the window bookkeeping so you don't choke when the OA timer ticks down.
Pattern tags
You know the problem.
Make sure you actually pass it.
Contains Duplicate II recycles across companies for a reason. It's easy-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Contains Duplicate II interview FAQ
Why does this have a 49% acceptance rate if it's marked easy?+
The constraint misread kills most submissions. Candidates spot 'duplicate' and implement a simple contains-duplicate solution, ignoring the 'within k indices' requirement. The actual algorithm is straightforward once you see the sliding window, but the gotcha in the problem statement catches people off guard.
Is this still asked at major tech companies?+
Yes. Companies including Google, Microsoft, Meta, Netflix, and Airbnb have all reported asking it. It's commonly used as a warm-up or early-stage screening problem to test if candidates can read constraints carefully and pick the right data structure.
What's the actual trick to solving it efficiently?+
Sliding window with a hash set. Maintain a set of the last k elements. When you add a new element, check if it's already in the set. If yes, return true. If the set size exceeds k, remove the leftmost element. This is O(n) time, O(min(n, k)) space.
How does this relate to the other topics listed?+
Array is the input structure. Hash Table (a set in this case) tracks elements in the current window. Sliding Window is the pattern. You need all three concepts working together, which is why it's a good screening question.
Should I practice this multiple times or just memorize the pattern?+
Memorize the sliding window plus hash set combo. The pattern is standard. The real prep is reading the problem statement twice so you don't skip the k constraint. If you blank during the OA, StealthCoder handles the implementation so you don't waste time.
Want the actual problem statement? View "Contains Duplicate II" on LeetCode →