Out-of-Order Logger Rate Limiter
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Google, September 2026. The input is up to 100000 events with timestamps up to 10^12, and they arrive out of order. That kills the naive scan of every prior accepted event per message. This is a per-message ordered-set problem wearing a rate limiter costume. For each message you keep the accepted timestamps in sorted order and ask one question: is anything accepted inside [t-9, t]? If you blank on the data structure choice during the live OA, StealthCoder runs invisibly as a safety net and hands you the structure.
The problem
A logger receives messages whose integer event timestamps may arrive out of order. Process the paired arrays timestamps and messages in input order. For an event with timestamp t and message m, print it exactly when no earlier accepted event for m has an event timestamp in the inclusive interval [t - 9, t]. An earlier-processed event whose timestamp is greater than t does not block this event. A rejected event does not update the accepted history, and decisions are never revised retroactively. Return one boolean per event: true when it prints and false when it is suppressed. Equal-timestamp events retain input order, and different messages are limited independently. Function shouldPrintOutOfOrder(timestamps: long[], messages: String[]) → boolean[] Examples Example 1 timestamps = [10,15,5,20] messages = ["foo","foo","foo","foo"] return = [true,false,true,true] The event at 10 prints, so the one at 15 is suppressed. Timestamp 5 then prints because the already processed timestamp 10 is later than its query interval. Timestamp 20 is ten seconds after the accepted event at 10, so it also prints. Example 2 timestamps = [20,11,12,21,30,22] messages = ["a","a","a","a","a","b"] return = [true,true,false,false,true,true] After timestamp 20 prints, the out-of-order event at 11 also prints. Timestamp 12 is blocked by 11, and timestamp 21 is blocked by 20. Timestamp 30 reaches the ten-second boundary, while message b has independent state. Constraints 1 <= timestamps.length == messages.length <= 100000. 0 <= timestamps[i] <= 1000000000000; timestamps need not be sorted. Each message contains from 1 through 50 lowercase English letters or digits. Use signed 64-bit arithmetic for timestamps and interval boundaries.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that only accepted events matter, and only the ones in the window [t-9, t]. Group by message with a hash map. For each message keep a sorted structure of accepted timestamps, like a TreeSet in Java or a sorted list with binary search. For event t, find the largest accepted timestamp <= t (floor). If it exists and is >= t-9, suppress. Otherwise accept and insert. Later accepted timestamps above t never block, which is the out-of-order catch. The classic pitfall is reusing the standard logger's last-seen-time map. That breaks when t is smaller than a stored value. Another pitfall is updating history on rejected events. Use long for everything. Total cost is O(n log n). StealthCoder is the hedge if the floor lookup escapes you mid-assessment.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Out-of-Order Logger Rate Limiter 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Out-of-Order Logger Rate Limiter FAQ
What's the trick in the Google out-of-order logger problem?+
Keep a sorted set of accepted timestamps per message. For each event, look up the largest accepted timestamp that is <= t. If it's within 9 of t, suppress. Otherwise accept and insert. Later timestamps never block, so a single last-seen value isn't enough.
Why does the simple last-timestamp map fail?+
It assumes time moves forward. In example 1, 5 arrives after 10 was accepted and still prints, because 10 is outside [-4, 5]. A single stored value would wrongly compare against 10 and could also miss an earlier accepted event that blocks a later arrival.
What complexity do I need with 100000 events?+
O(n log n) overall. A hash map from message to an ordered structure gives a log-time floor lookup and insert per event. Scanning all prior accepted events per message is O(n^2) in the worst case and will be too slow.
Do rejected events change the state?+
No. Only accepted events are stored. A rejected event is never added, and earlier decisions are never revised. Example 2 shows this: 12 is blocked by 11, and 12 doesn't then block anything else.
How do I prep for this in 48 hours?+
Practice ordered-set floor queries in your language: TreeSet.floor in Java, bisect in Python, std::set upper_bound in C++. Then hand-trace both examples, including the boundary case where 30 prints after 20 because the gap equals 10. Watch for 64-bit overflow in languages with 32-bit ints.