FastPrepMost-Frequent Events in an Arrival Window
Problems/Most-Frequent Events in an Arrival Window

Most-Frequent Events in an Arrival Window

Google logoGoogle● HardFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report says "Please extract the most frequent one" and asks for its timestamps.

It adds an event queue with a limit, but does not give tie rules or a finite output format. Here, the oldest arrival leaves first, ties use ASCII message order, and timestamps can repeat or decrease. Return the winner after each arrival and the final winner's active timestamps in arrival order.

Our version is about 90% the same as the reported question.

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 0 contains the winning message after each arrival.
  • Row 1 contains 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

Interview reports that mention this question

  • Google L4 ML Loops and Team Matching: 8 Experiences (Part 2 of 4)

Google interview experiences

  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
  • Google AI Coding Interview and AI OA: 2 Experiences
  • Google SWE Intern Interview Results Timeline: 13 Experiences
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public String[][] frequentEventWindows(String[] messages, int[] timestamps, int windowSize) {
        // Write your code here.
    }
}
Checking account…