FastPrep15-Minute Chat Session Tracker
Problems/15-Minute Chat Session Tracker

15-Minute Chat Session Tracker

OpenAI logoOpenAI● HardFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem is backed by a real OpenAI onsite report. The report described an in-memory, single-threaded chat analytics service with a 15-minute window. It had recent-interaction queries, active sessions, events out of order, and limited memory. The finite command format and the output strings below are our own interface choices.

Implement trackChatSessions. Process the operations in input order. Each operation is one of:

  • INTERACT userId chatId timestamp: record an interaction.
  • END userId chatId timestamp: record an explicit session end.
  • COUNT userId chatId: output the number of retained interactions for that pair.
  • ACTIVE userId: output the number of active chats for that user.

Event timestamps are integer minutes and may arrive out of order. Let T be the largest event timestamp seen so far. The current window is the inclusive interval [T - 14, T]. When an event advances T, discard expired state. A late event with timestamp below T - 14 is ignored.

A chat is active exactly when its latest retained INTERACT timestamp is in the current window and is strictly greater than its latest END timestamp. A later interaction may reactivate a chat. Return one decimal string for every COUNT or ACTIVE operation, in query order. Queries before any event return 0.

Your retained state must be proportional to events and chats in the current 15-minute window, not the complete history.

Function

trackChatSessions(operations: String[]) → String[]

Examples

Example 1

operations = ["INTERACT u1 7 1","INTERACT u1 7 5","COUNT u1 7","ACTIVE u1","END u1 7 6","ACTIVE u1","INTERACT u1 8 20","COUNT u1 7","ACTIVE u1"]return = ["2","1","0","0","1"]

The first two interactions are counted while T=5. The end event deactivates chat 7. Advancing to minute 20 expires every event before minute 6, so chat 7 has count zero and only chat 8 is active.

Example 2

operations = ["INTERACT u1 1 30","END u1 1 25","ACTIVE u1","END u1 1 35","INTERACT u1 1 33","ACTIVE u1","INTERACT u1 1 36","ACTIVE u1","COUNT u1 1"]return = ["1","0","1","3"]

Late arrivals are interpreted by timestamp. The end at 25 does not kill the interaction at 30. The end at 35 is later than the late interaction at 33, but the interaction at 36 reactivates the chat. All three interactions remain inside [22,36].

Constraints

  • 0 <= operations.length <= 100000
  • Identifiers are non-empty ASCII tokens without whitespace.
  • 0 <= timestamp <= 10^9.
  • Every operation has one of the four valid formats.
  • For one chat, no two events share a timestamp.

More OpenAI Onsite Interview questions

  • Sparse Plant Infection SimulationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Rectangle Point Coverage CountsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Message Event AggregationPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Segmented Durable Key-Value StorePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Durable Work Queue OperationsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Versioned Social NetworkPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Budgeted API Inference with Out-of-Order FeedbackONSITE INTERVIEW · Seen Oct 2026
  • Plant Infection Simulation, Part 4: Death CountdownPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Count Friend CirclesPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Incremental Hard Attention with a KV CachePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • LRU Cache with TTLAutodesk · ONSITE INTERVIEWAutodesk interview questions
  • Capacity-Limited Timed CacheNetflix · PHONE SCREENNetflix interview questions
  • Tiered Expiring Item StoreHudson River Trading · PHONE SCREEN · ONSITE INTERVIEWHudson River Trading interview questions
  • Tiered Expiring Item StoreAkuna Capital · PHONE SCREENAkuna Capital interview questions
  • Multi-Level Inventory Storage SystemOptiver · OA · PHONE SCREENOptiver interview questions
  • Key-Value Store GET and PUT QPSDatabricks · PHONE SCREENDatabricks interview questions
  • Limit Order Book Matching EngineCitadel · PHONE SCREENCitadel interview questions
  • Document Enrichment Stream AggregatorBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Windowed Key-Value MapConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
  • Expiring Key SetAmazon · ONSITE INTERVIEW
All OpenAI interview questionsSee OpenAI hiring insights
Saved
class Solution {
    public String[] trackChatSessions(String[] operations) {
      // write your code here
    }
}
Checking account…