Reported September 2026
Googlesimulation

Random Picks Excluding Recent Values

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

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

Google, September 2026. The input sizes here are the whole story: up to 2 * 10^5 draws and 10^5 picks, so rescanning the last k accepted values for every draw will time out when k is big. This one is a simulation with a sliding window of recent accepted values, backed by a hash set for instant lookups. It reads like a toy problem, but the trap is in the bookkeeping. If you blank on the data structure choice during the OA, StealthCoder runs invisibly on your desktop as a safety net and gives you the solution in real time.

The problem

You are given an array of distinct integer values, an exclusion length k, a requested number of accepted picks picks, and recorded random candidate indices draws.
Process draws from left to right. A candidate index selects values[draws[i]]. Reject that candidate when its value appears among the most recent k accepted values. Otherwise, accept it, append it to the result, and update the recent-value history.
Rejected candidates do not change the recent-value history. Stop as soon as picks values have been accepted and return them in acceptance order.
When k is 0, every candidate is accepted. The input guarantees that draws contains enough acceptable candidates to produce the requested result.

Function
pickWithoutRecent(values: int[], k: int, picks: int, draws: int[]) → int[]

Examples
Example 1
values = [10,20,30]
k = 1
picks = 4
draws = [0,0,1,1,2,0]
return = [10,20,30,10]
Accept 10, reject the repeated 10, accept 20, reject the repeated 20, then accept 30 and 10.
Example 2
values = [1,2,3,4]
k = 2
picks = 5
draws = [0,1,0,2,1,3,0]
return = [1,2,3,4,1]
After accepting 1 and 2, the next 1 is rejected. After accepting 3, the next 2 is still recent and is rejected.
Example 3
values = [5,7]
k = 0
picks = 4
draws = [1,1,0,1]
return = [7,7,5,7]
With k = 0, no accepted value is excluded, so every recorded candidate is returned.

Constraints
1 <= values.length <= 10^5.
All values are distinct and satisfy -10^9 <= values[i] <= 10^9.
0 <= k < values.length.
1 <= picks <= 10^5.
picks <= draws.length <= 2 * 10^5.
0 <= draws[i] < values.length.
The recorded candidates contain enough accepted values to produce exactly picks results.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is keeping two structures in sync: a queue (or the result array itself) holding the last k accepted values, and a hash set for O(1) membership checks. For each draw, look up values[draws[i]]. If it's in the set, skip it. Otherwise append it to the result, add it to the set, and if the window now exceeds k, evict the oldest accepted value from the set. Total work is O(draws). The common pitfall is updating history on rejected draws, which the statement explicitly forbids. Another is the k = 0 case: if you add then evict, make sure the set stays empty, or just short-circuit and accept everything. Since values are distinct, checking the value or the index is equivalent. Stop the moment you hit picks accepted results. If the window logic slips under pressure, StealthCoder is the hedge for the live OA.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Random Picks Excluding Recent 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. If you're reading this with an OA window open, you're who this was built for.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Google reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Random Picks Excluding Recent Values FAQ

How hard is this Google OA question really?+

Easy to medium. There's no clever algorithm, just a clean simulation. The difficulty is efficiency and edge cases. A naive scan of the last k accepted values per draw is O(draws * k), which fails at 10^5 scale.

What's the trick to passing all test cases?+

Pair a queue or the result array with a hash set. Check membership in O(1), accept and add on success, and evict the value that falls out of the last k window. Never touch history on a rejected draw.

How do I handle k = 0?+

With k = 0 nothing is excluded, so every draw is accepted. Either special-case it and return the first picks mapped values, or make sure your eviction logic removes the value immediately so the set stays empty.

Does the window count rejected draws?+

No. Only accepted values count toward the most recent k. Example 2 shows it: after accepting 3, the value 2 is still within the last two accepted values, so it's rejected even though draws happened in between.

How do I prepare for this in 48 hours?+

Practice sliding-window-plus-hash-set simulations. Write this one from scratch twice, test the three examples, then add k = 0 and k = values.length - 1 cases. Keep it O(draws) and stop early at picks results.

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

OA at Google?
Invisible during screen share
Get it