Most-Frequent Events in an Arrival Window
Updated
Problem statement
The parallel arrays messages and timestamps describe events in arrival order. Process each arrival by adding it to a queue. If the queue exceeds windowSize, remove its oldest arrival. Timestamps may decrease or repeat; they do not control eviction.
After every arrival, choose the active message with the highest frequency. For this exercise, break equal-frequency ties by the lexicographically smallest case-sensitive message.
Return a two-row string array:
- Row
0contains the winning message after each arrival. - Row
1contains the active timestamps for the final winning message, written as decimal strings in arrival order.
When the input is empty, return [[],[]]. If the window is larger than the number of events received, keep every event received so far.
Function
frequentEventWindows(messages: String[], timestamps: int[], windowSize: int) → String[][]Examples
Example 1
messages = ["error_1","error_1","error_2"]timestamps = [123,234,456]windowSize = 3return = [["error_1","error_1","error_1"],["123","234"]]The final queue contains two error_1 events and one error_2 event. error_1 wins after every arrival, and its final timestamps are 123 and 234.
Example 2
messages = ["error_1","error_1","error_1"]timestamps = [123,345,234]windowSize = 2return = [["error_1","error_1","error_1"],["345","234"]]The third arrival evicts the first event at timestamp 123. The surviving timestamps remain in arrival order, 345 then 234, even though they decrease.
Constraints
- 0 <= messages.length <= 5000
- messages.length == timestamps.length
- 1 <= messages[i].length <= 50
- Every message uses only ASCII letters, decimal digits and underscores.
- 0 <= timestamps[i] <= 10^9
- 1 <= windowSize <= 5000
More Google Phone Screen questions
- 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
- Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026
- Minimum Total Layover WaitPHONE SCREEN · Seen Nov 2026
- Reach a Destination Through Scheduled FlightsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- 15-Minute Chat Session TrackerOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Smallest Range Covering Elements from K ListsSnap Inc. · PHONE SCREENSnap Inc. interview questions
- Key-Value Store GET and PUT QPSDatabricks · PHONE SCREENDatabricks interview questions
- Per-Client API Rate LimiterDocker · PHONE SCREEN
- Per-Client Sliding-Window Rate LimiterCVS Health · PHONE SCREEN
- Sliding-Window Rate LimiterUber · PHONE SCREENUber interview questions
- Recent Advertisement Click CountsAmazon · PHONE SCREEN
- Rate Limiter Sliding Window With Per-Entity LimitsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Transcript Window MetricsSesame · PHONE SCREEN
- Transaction Logs — Trigger / Resolve AlertsStripe · PHONE SCREENStripe interview questions