Reported October 2024
Amazonhash table

Make All Elements Distinct

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

Amazon's October OA threw this one at candidates and it landed hard. You're given an array and need to make every element distinct by removing the minimum number of elements. No fancy string manipulation, no matrix traversal. It's pure array logic, and the trap is overthinking it. If you blank on the pattern during the live OA, StealthCoder will surface the core insight fast so you don't waste 20 minutes going in circles.

Pattern and pitfall

The trick here is greedy. You can't rearrange, only remove. So you scan left to right, keep elements you haven't seen, and drop duplicates on sight. Use a hash set to track what you've already kept. Candidates often waste time considering whether to keep the first occurrence or the last, or trying to optimize which duplicate to remove. Wrong frame. Just track seen elements and count the removals. This is greedy plus hash-table thinking. If you hit this live and freeze on the approach, StealthCoder will hand you the hash-set pattern so you can code it without the five-minute paralysis.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Make All Elements Distinct cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Make All Elements Distinct FAQ

Do I have to keep the original order of elements?+

Yes. You're removing elements, not rearranging. Scan left to right, keep the first occurrence of each value, drop any duplicates you see after. Order stays intact.

What's the trick Amazon is really testing?+

Hash set membership and greedy selection. They want to see if you can identify that one pass with tracking is enough. No sorting, no DP. Just clean iteration and a set.

Is this actually hard or does it just sound hard?+

It's medium difficulty because the wording can trip you up. The algorithm itself is straightforward once you see it. The OA score depends on clean code and edge cases, not the core logic.

How do I prepare for this in 48 hours?+

Practice one or two hash-set problems on arrays. Focus on single-pass solutions. Understand when you can solve something in one loop versus needing two. That's the real skill being tested.

Will Amazon ask follow-ups like space or time optimization?+

Likely. You'll use O(n) time and O(n) space for the set. Be ready to explain why that's optimal and why you can't do better on space without sorting.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it