Logger Rate Limiter with Every-Arrival History
Updated
Problem statement
Messages arrive at integer timestamps that never go backward. For each pair [timestamp,message], print the message exactly when it has not arrived during the previous 10 seconds: if its prior arrival time is last, require timestamp-last >= 10.
Whether printed or skipped, every arrival becomes the new last time for that message. Different messages are tracked independently.
Return one boolean per arrival, true when printed.
Function
shouldPrintMessages(timestamps: int[], messages: String[]) → boolean[]Examples
Example 1
timestamps = [0,5,12]messages = ["x","x","x"]return = [true,false,false]The arrival at 5 is suppressed but resets history, so 12 is only seven seconds later and is also suppressed.
Example 2
timestamps = [1,2,11,12]messages = ["a","b","a","b"]return = [true,true,true,true]Each message's arrivals are exactly ten seconds apart.
Example 3
timestamps = []messages = []return = []No arrivals produce no decisions.
Constraints
0 <= timestamps.length = messages.length <= 200000.- Timestamps are nondecreasing integers in
[0,10^9]. - Messages are nonempty case-sensitive strings.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Propagating Fraud DetectorAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions
- Order and Batch Open-Close LifecycleHudson River Trading · PHONE SCREENHudson River Trading interview questions
- Pins Violation Log QueriesPinterest · PHONE SCREENPinterest interview questions
- Resource Reconciler: Plan and Apply CreatesPerplexity AI · PHONE SCREENPerplexity AI interview questions
- Realized Gains from a Real-Estate Transaction StreamKikoff · PHONE SCREENKikoff interview questions
- Process On-Call Routing OperationsOpenAI · PHONE SCREENOpenAI interview questions
- Batched Key Fetch CallbacksAnrok · PHONE SCREEN
- Earliest Car for Each PassengerWhatNot · PHONE SCREENWhatNot interview questions
- Stateful Paginated Fetch NLyft · PHONE SCREENLyft interview questions