Random Pick Index
A medium-tier problem at 65% community acceptance, tagged with Hash Table, Math, Reservoir Sampling. Reported in interviews at Meta and 0 others.
Random Pick Index is a medium-difficulty problem that hits a real constraint: you need to return a uniformly random index for a given value in an array, but you can't precompute or store the indices upfront in a way that wastes space. Meta asks this one, and it's deceptively simple on the surface. The acceptance rate sits at 64.5%, which means a quarter of people who submit hit a wall on the randomization logic or space complexity. If you blank on reservoir sampling during your assessment, StealthCoder surfaces a working solution in seconds, invisible to the proctor.
Companies that ask "Random Pick Index"
Random Pick Index 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 gotcha here is that you're asked to pick a random index for a value each time the method is called, and you don't know all the indices in advance. The naive approach (build a list of all indices) eats memory. Instead, you use reservoir sampling: iterate through the array once, keep a count of matches, and use math to pick uniformly at random. The trick is the probability calculation: if you've seen k matches so far, accept the current match with probability 1/k. It feels strange, but it guarantees each index has equal odds. Hash Table and Math combine here, though the real insight is recognizing this as a randomized algorithm problem. Common pitfall: folks try to precompute or use a HashMap of index lists, which defeats the space-efficient point. If this pattern hits your OA and the randomization logic isn't clicking, StealthCoder runs invisibly during screen share and shows you the sampling approach.
Pattern tags
You know the problem.
Make sure you actually pass it.
Random Pick Index 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.
Random Pick Index interview FAQ
How do I ensure each index has equal probability of being picked?+
Use reservoir sampling. When you find the k-th occurrence of the target value, accept it as the result with probability 1/k. This guarantees uniform distribution across all indices. The math is counterintuitive but proven. Meta cares about this correctness, not just a working solution.
Should I precompute all indices in a HashMap?+
No. That's the naive trap and wastes O(n) space. The problem wants you to avoid that. Iterate the array each call and apply reservoir sampling. It's O(n) time per call but O(1) space, which is the real constraint.
Why is the acceptance rate 64.5% if this is medium difficulty?+
Most people recognize hash tables but miss the reservoir sampling pattern. They either try to precompute (wrong approach) or implement randomization incorrectly. The insight isn't obvious on first read, which costs time under pressure.
What's the difference between this and a standard random picker?+
Standard random picker assumes you know all valid indices upfront. Here you don't. Reservoir sampling lets you pick uniformly without storing an index list. It's a specific randomized algorithm, not just Math.random() on an array.
Is this still asked by Meta in real OAs?+
Meta is the only company listed for this problem. It appears in their assessment rotation. If you're interviewing there and haven't seen reservoir sampling, you're at risk. Study the pattern or have a safety net ready.
Want the actual problem statement? View "Random Pick Index" on LeetCode →