Insert Delete GetRandom O(1) - Duplicates allowed
A hard-tier problem at 36% community acceptance, tagged with Array, Hash Table, Math. Reported in interviews at Peloton and 6 others.
You're staring at a data structure problem that demands constant-time insert, delete, and random retrieval with duplicates allowed. Peloton, Yelp, Affirm, and LinkedIn have all asked this one. The acceptance rate is around 36%, and most candidates fail by trying to build something that collapses under the duplicate constraint. The trick is counterintuitive enough that you'll either see it or you won't, and there's almost no middle ground. If you hit this on your live assessment and freeze, StealthCoder runs invisibly during screen share and hands you a working solution in seconds.
Companies that ask "Insert Delete GetRandom O(1) - Duplicates allowed"
Insert Delete GetRandom O(1) - Duplicates allowed 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 because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.
Get StealthCoderThe problem demands O(1) time for all three operations, which kills naive hash table or list approaches as soon as duplicates enter the picture. The core insight: pair a hash map (values to sets of indices) with a dynamic array, then swap-to-back during deletion to keep the array dense and the random access constant. When you delete, you move the last element into the gap, update its index in the hash map, then pop. Candidates typically either abandon O(1) entirely when duplicates appear or try to maintain sorted order, killing the time bound. The tricky part isn't the algorithm itself, it's holding the mental model of why swapping works even with duplicates and how the hash map of sets prevents collisions on lookup. If you haven't drilled this pattern and it lands on your OA, StealthCoder is your insurance.
Pattern tags
You know the problem.
Make sure you actually pass it.
Insert Delete GetRandom O(1) - Duplicates allowed 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 because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Insert Delete GetRandom O(1) - Duplicates allowed interview FAQ
Is this problem still asked at big tech companies?+
Yes. Seven companies in the input data have asked it, including LinkedIn, Citadel, and TikTok. The acceptance rate is around 36%, so it's selective but not rare. It shows up more often in system design and infrastructure roles where you need efficient data structure thinking.
What's the main trick candidates miss?+
They can't bridge insert, delete, and getRandom all at O(1) with duplicates present. The swap-to-back pattern only clicks when you pair it with a hash map of sets to track indices by value. Without that pairing, the approach falls apart under duplicate edge cases.
Why is this rated HARD when the algorithm is short?+
The code is brief, but the mental model is not. You must keep three invariants in sync: the array order, the hash map indices, and the set cardinality. One mistake in the swap logic or index update cascades into bugs. It's a precision problem, not a complexity problem.
How does this relate to the Array and Hash Table topics?+
You use both simultaneously and symmetrically. The array is your backing store for O(1) random access and dense iteration. The hash table is your index tracker to recover O(1) deletion. Neither alone is enough; the pairing is the design.
Should I memorize this solution or understand the pattern?+
Understand the swap-to-back pattern. Once you see it, you can rebuild the code. Memorization fails under follow-ups like 'what if we add a weight or priority to each element'. The pattern is reusable; the code is not.
Want the actual problem statement? View "Insert Delete GetRandom O(1) - Duplicates allowed" on LeetCode →