FastPrepChat Event Counts in Recent Window
Problems/Chat Event Counts in Recent Window

Chat Event Counts in Recent Window

OpenAI logoOpenAI● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are tracking chat events. You are given an array of commands, commands. Each entry is one command, and you handle the commands in the order they appear. There are two kinds of command:

  • EVENT userId chatId timestamp: record that userId had an event in chat chatId at minute timestamp.
  • COUNT userId chatId timestamp: count the events recorded so far for that exact pair of userId and chatId that happened in the last 15 minutes.

The last 15 minutes includes the query minute itself. An event at timestamp - 15 still counts. An event older than that does not count, and neither does an event after timestamp. A COUNT does not change anything. It only looks at the events recorded before it.

Return one number for each COUNT command, in the order the commands appear.

For example, take EVENT u1 c1 0, EVENT u1 c1 10, COUNT u1 c1 16. At minute 16 the window runs from minute 1 to minute 16. The event at minute 0 is too old, and the event at minute 10 counts, so the answer is 1.

Function

chatEventCounts(commands: String[]) → int[]

Examples

Example 1

commands = ["EVENT u1 c1 0", "EVENT u1 c1 10", "EVENT u1 c2 12", "COUNT u1 c1 14", "COUNT u1 c1 16", "EVENT u1 c1 20", "COUNT u1 c1 25", "COUNT u1 c2 25"]return = [2, 1, 2, 1]

There are four COUNT commands, so the answer has four numbers. At minute 14 for u1 and c1, the events at minutes 0 and 10 are both inside minutes -1 to 14, so the count is 2. At minute 16 the window is minutes 1 to 16, so the event at minute 0 is too old and only the event at minute 10 is left: 1. At minute 25 for u1 and c1, the window is minutes 10 to 25, which holds the events at minutes 10 and 20: 2. At minute 25 for u1 and c2, the window holds only the event at minute 12: 1. The answer is [2, 1, 2, 1].

Constraints

  • Each command is EVENT userId chatId timestamp or COUNT userId chatId timestamp, with single spaces between the four parts.
  • Timestamps are integer minutes and commands are processed in input order.
  • Counts are keyed by both user id and chat id.

More OpenAI Phone Screen questions

  • Secret Number Search with One-Call-Delayed FeedbackPHONE SCREEN · Seen Nov 2026
  • Determine the Winner of Three-Card HandsPHONE SCREEN · Seen Nov 2026
  • Grid Infection with Recovery After D DaysPHONE SCREEN · Seen Nov 2026
  • Sparse Plant Infection SimulationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Light Source Hits: Sample, Compare, and FitPHONE SCREEN · Seen Nov 2026
  • Rectangle Point Coverage CountsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Adaptive Calibration ErrorPHONE SCREEN · Seen Nov 2026
  • Elevator Scheduling SimulationPHONE SCREEN · Seen Nov 2026
  • Evaluate Noisy AnnotatorsPHONE SCREEN · Seen Oct 2026
  • Network Endpoint or Cycle BoundaryOA · PHONE SCREEN · Seen Oct 2026

Similar questions at other companies

  • Log Analyzer: Busiest Service in a Rolling WindowByteDance · PHONE SCREENByteDance interview questions
  • Per-Client API Rate LimiterDocker · PHONE SCREEN
  • Longest Substring Without Repeating CharactersAngel One · PHONE SCREEN
  • Longest Substring Without Repeating CharactersNykaa · PHONE SCREENNykaa interview questions
  • Longest Substring Without Repeating CharactersIBM · PHONE SCREENIBM interview questions
  • Per-Client Sliding-Window Rate LimiterCVS Health · PHONE SCREEN
  • Compact Conversations by Unique ListingsSierra · PHONE SCREENSierra interview questions
  • Implement a Rate LimiterRoblox · PHONE SCREENRoblox interview questions
  • Implement a Rate LimiterAtlassian · PHONE SCREENAtlassian interview questions
  • Longest Substring Without Repeating CharactersTikTok · PHONE SCREENTikTok interview questions

OpenAI interview experiences

  • OpenAI OA: What It Tests (2026)
All OpenAI interview questionsSee OpenAI hiring insights
Saved
class Solution {
    public int[] chatEventCounts(String[] commands) {
        // write your code here
    }

}
Checking account…