Find All Duplicates in an Array
A medium-tier problem at 76% community acceptance, tagged with Array, Hash Table. Reported in interviews at Pocket Gems and 1 others.
Find All Duplicates in an Array is a medium-difficulty problem that shows up in Google and Pocket Gems interviews. The trick here is that the problem statement usually hides a critical constraint: the array length is n, values range from 1 to n-1, and you can't use extra space. Most candidates see "find duplicates" and reach for a hash set or hash map, which works but misses the point. The assessment wants you to exploit the array indices themselves. With a 76% acceptance rate, this problem separates people who pattern-match from people who read constraints. StealthCoder solves it in seconds if you hit it live and freeze on the indexing trick.
Companies that ask "Find All Duplicates in an Array"
Find All Duplicates in an Array 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 an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too.
Get StealthCoderThe intended solution uses the array as its own hash table by treating values as indices. When you see a number, you mark that index as visited by flipping it negative (or toggling a bit, depending on language). If you encounter an already-negative value at that index, you've found a duplicate. This is a marker-in-place technique that requires O(1) space and O(n) time. The naive hash table approach is correct but doesn't satisfy the space constraint some assessments impose. The pitfall is not reading the constraint carefully and then wasting mental cycles on a solution that technically works but fails the interview's hidden requirement. If you blank on the indexing trick during a live OA, StealthCoder reads the problem, spots the n and 1 to n-1 bounds, and surfaces the marker solution instantly, invisible to the proctor.
Pattern tags
You know the problem.
Make sure you actually pass it.
Find All Duplicates in an Array recycles across companies for a reason. It's medium-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 an Amazon engineer who watched the leaked-problem repo become an industry secret. He decided you should have it too. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Find All Duplicates in an Array interview FAQ
Is this problem actually asked at Google?+
Yes. Google is listed in the top companies that ask it. It's also in Pocket Gems interviews. It's a lower-frequency ask overall but popular enough that you should know the pattern, especially if you're targeting large tech firms.
Can I just use a hash set and not worry about the space constraint?+
Depends on the specific OA. Hash set works and passes most automated judges. But Google and other strict interviewers often emphasize the O(1) space requirement in the problem statement. Read the constraints. If space is called out, you need the in-place marker trick.
What's the core trick I need to drill?+
Treat the array values as indices and use the array itself as a visited marker. When you process a value x, go to index abs(x) and flip the sign at that location. If the value is already negative, x is a duplicate. This pattern shows up across many array problems.
Does the acceptance rate of 76% mean this is easier than it looks?+
No. High acceptance usually means most people solve it with a hash table, which passes the automated tests. But if you hit it at a top company, the constraint nuance matters. The 76% masks a split between correct-but-suboptimal and optimal solutions.
How does this relate to Hash Table and Array topics?+
Officially it's both, but the Array angle is deeper. Hash Table is the obvious tool. Array tests whether you see the index-as-key trick. Master the index-marking pattern and you unlock a whole class of array problems that seem to need hash tables but don't.
Want the actual problem statement? View "Find All Duplicates in an Array" on LeetCode →