First Unique Event in a Stream
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt at this Google OA, reported in November 2025, is rescanning the whole prefix after every event. With up to 200000 events, that's quadratic and it times out. The problem is First Unique Event in a Stream: for each prefix, return the earliest value seen exactly once, or an empty string. It's a hash map plus a queue, and the trick is small. If you blank on the live OA, StealthCoder runs invisibly as a safety net and gives you the pattern while you type.
The problem
You receive a stream of string events in order. After processing each event, report the earliest event value that has appeared exactly once in the entire prefix processed so far. If the current prefix has no event value with frequency one, report the empty string for that position. Return one answer for every processed event. Function firstUniqueAfterEachEvent(events: String[]) → String[] Examples Example 1 events = ["a","b","a","c"] return = ["a","a","b","b"] After the third event, a is repeated, so b becomes the earliest value seen exactly once. Adding c does not change that earliest unique value. Example 2 events = ["x","x","y","y"] return = ["x","","y",""] The second and fourth prefixes contain no value with frequency one, so their answers are empty strings. Example 3 events = [] return = [] An empty stream produces no prefix answers. Constraints 0 <= events.length <= 200000 1 <= events[i].length <= 30 Each event contains lowercase English letters.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Keep a frequency map and a queue of values in arrival order. For each event, increment its count and push it onto the queue if it's new, or just push it every time. Then pop from the front while the front value has a count above one. The front of the queue is your answer, or the empty string if the queue is empty. Each element is pushed once and popped at most once, so the whole thing is O(n). The common pitfall is removing items from the middle of a list when a value repeats. Don't. Lazy deletion from the front is enough, because only the front matters. Another trap is forgetting the empty string output for prefixes with no unique value, and the empty input case. StealthCoder is the hedge for the live OA if the queue idea slips your mind under pressure.
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 First Unique Event in a Stream 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
You've seen the question.
Make sure you actually pass Google's OA.
Google 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.
First Unique Event in a Stream FAQ
How hard is this Google OA question really?+
Easy to medium. The idea is a frequency map plus a queue with lazy removal. If you've seen the first unique character problem, this is the streaming version of it. The only real difficulty is avoiding the quadratic rescan at 200000 events.
What's the trick to getting O(n)?+
Never rescan. Store arrival order in a queue and counts in a hash map. After each event, pop the front while its count is above one. The front is the answer. Each value enters and leaves the queue at most once, so total work stays linear.
What edge cases should I test?+
Test the empty array, which returns an empty array. Test all-duplicate streams like x, x, y, y, where answers alternate between a value and an empty string. Also test a value that repeats long after it first appeared, to confirm the front pops correctly.
Can I use a linked hash map or ordered set instead?+
Yes. An insertion-ordered map where you delete a key once its count hits two works too, and the first key is your answer. A queue with lazy deletion is simpler and works in any language without special containers.
How do I prepare for this in 48 hours?+
Write the queue and hash map solution from scratch twice, then trace Example 1 by hand. Practice the related first unique character pattern and sliding-window-style stream problems. Focus on clean loops and returning an empty string, not on memorizing code.