Contains Duplicate III
A hard-tier problem at 24% community acceptance, tagged with Array, Sliding Window, Sorting. Reported in interviews at Palantir Technologies and 3 others.
Contains Duplicate III hits different from the standard duplicate problem. You're not just finding repeats, you're hunting for two distinct indices i and j where the absolute difference between indices is at most k and the absolute difference between values is at most t. Palantir, Airbnb, Netflix, and Yandex all ask this. The acceptance rate sits at 24%, which means most candidates either miss the constraint interplay or burn time on a brute force that times out. If this lands in your OA and you freeze on the pattern, StealthCoder surfaces the working solution instantly, invisible to the proctor.
Companies that ask "Contains Duplicate III"
Contains Duplicate III 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. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share.
Get StealthCoderThe trap is treating this as a basic duplicate search. Brute force checking every pair within the index window k blows up to O(n*k), which fails on large inputs. The winning approach uses a sliding window paired with either bucket sort logic or an ordered set to track values in the current window. You need to recognize that once you maintain a window of size k, the problem reduces to finding if any two values in that window differ by at most t. Many candidates see 'sorting' in the topic list and think global sort, which doesn't help here. The real move is understanding how bucket partitioning or tree-based range queries handle the value constraint. When you're grinding this under live conditions and the window mechanics aren't clicking, StealthCoder cuts through that friction with a verified solution.
Pattern tags
You know the problem.
Make sure you actually pass it.
Contains Duplicate III recycles across companies for a reason. It's hard-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. Built by an engineer at a top-10 tech company who can solve these problems cold but didn't want to trust himself in a 90-minute screen share. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Contains Duplicate III interview FAQ
Is this problem actually harder than it looks on paper?+
Yes. The 24% acceptance rate reflects that. Most people understand the constraints individually, but coordinating both the index window k and value range t simultaneously trips them up. The algorithm itself isn't that long, but recognizing which data structure solves it efficiently (bucket sort, balanced BST, or ordered set) is the real test.
Do I need to know bucket sort to pass this?+
No, but it helps. Bucket sort is one clean solution path. An ordered set (tree-based) works equally well and is more intuitive for some. The key is understanding that you need a data structure that supports range queries within the value window t, not just membership checks.
How does the sliding window constraint change the problem?+
It confines your search space. You only care about elements within the last k indices, not the entire array. This lets you maintain a window of candidates and drop old ones, keeping memory and time reasonable. Miss this and you're solving a much harder problem.
What's the most common mistake candidates make?+
Treating the two constraints (index difference and value difference) as independent. They check index distance correctly but then do a naive linear scan for value distance within the window, which is O(n*k) and times out. The solution requires coupling them in a single data structure.
Is this still asked at Palantir, Airbnb, and Netflix?+
Yes, it's consistently reported at all four companies listed. At that tier, they're testing whether you recognize the pattern under pressure and can code a non-obvious data structure choice cleanly in 45 minutes.
Want the actual problem statement? View "Contains Duplicate III" on LeetCode →