Randomized Collection with Duplicate Values
Reported by candidates from Okta's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Okta OA reported in September 2026 is a Randomized Collection with Duplicate Values, and the whole thing hinges on one data structure combo: a dense array plus a hash map from value to a set of indices. Insert, remove and indexed get all need expected O(1). If you've seen the classic insert-delete-getRandom with duplicates, this is that, with the random number injected so output is deterministic. You've got a couple of days, so know the swap-with-last trick cold. If you blank mid-assessment, StealthCoder runs invisibly on your desktop as a safety net while you work the problem.
The problem
Process a finite operation sequence against a collection that stores duplicate integers. INSERT adds values[i] and returns whether that value was absent before the operation. REMOVE removes the oldest still-present occurrence of values[i] and returns whether an occurrence existed. GET returns the element at index floorMod(values[i], size) in the collection's internal dense array. A GET operation is provided only when the collection is non-empty. Removal fills the removed dense-array slot with the previous final element before shortening the array. Return one string per operation: "true" or "false" for mutations and the selected decimal integer for GET. The injected integer on GET models a random-number source. Design insertion, removal, and indexed selection to run in expected O(1) time. Function randomizedCollectionOperations(operations: String[], values: int[]) → String[] Examples Example 1 operations = ["INSERT","INSERT","INSERT","REMOVE","GET"] values = [1,1,2,1,3] return = ["true","false","true","true","1"] After removing one 1, the dense array contains two values. The injected draw 3 selects index 1. Example 2 operations = ["REMOVE","INSERT","GET"] values = [5,5,-1] return = ["false","true","5"] The first removal fails. With one stored value, every injected draw selects that value. Example 3 operations = ["INSERT","INSERT","REMOVE","REMOVE","INSERT"] values = [7,7,7,7,7] return = ["true","false","true","true","true"] After both occurrences are removed, inserting 7 again reports that it was absent. Constraints operations.length == values.length. 1 <= operations.length <= 100000. Every operation is INSERT, REMOVE, or GET. -10^9 <= values[i] <= 10^9. Every GET occurs when the collection is non-empty.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: keep an array of values and a map from value to the set of its positions in the array. Insert appends and adds the index to the set, returning true if the set was empty before. Remove takes an index of the value from the set, moves the last array element into that slot, updates the moved element's index set, then pops the array. GET is just arr[floorMod(v, size)]. The pitfall is the twist here: remove must drop the oldest still-present occurrence, so a plain unordered set may not match the expected output. Use an ordered structure per value, or reason carefully about which index is oldest after swaps. Also handle the case where the removed slot is the last element, or you'll delete and re-add the same index. And floorMod must be non-negative for negative inputs. StealthCoder is the hedge if the index bookkeeping falls apart under the live clock.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Randomized Collection with Duplicate Values 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 StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as insert delete getrandom o1 duplicates allowed. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Okta's OA.
Okta 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.
Randomized Collection with Duplicate Values FAQ
What's the core trick in the Okta randomized collection problem?+
Pair a dense array with a hash map from value to its indices. Removal swaps the target slot with the last array element, fixes the moved element's index entry, then pops. That keeps insert, remove and indexed get at expected O(1).
How is this different from the classic LeetCode version?+
The random pick is replaced by an injected integer, so GET returns arr[floorMod(v, size)] deterministically. Removal also targets the oldest still-present occurrence, and the fill rule for removed slots is spelled out. Your outputs must match exactly.
What mistakes break the solution most often?+
Forgetting the case where the removed index is the last slot, not updating the moved element's index set, and using plain modulo on negative values. Also returning insert true/false based on the wrong check. It should be true only if the value was absent before.
How hard is this really?+
Medium to hard on the bookkeeping, not on the idea. The concept is short, but duplicates plus swap-removal plus the oldest-occurrence rule create many edge cases. Trace Example 1 and Example 3 by hand before submitting.
How do I prepare in 48 hours?+
Write the structure from scratch twice without notes. Test on repeated values, removing from an empty collection, removing the last element, and negative GET values. Then run the three given examples. If the oldest-occurrence ordering confuses you, sketch the array after each step.