Reported May 2026
OpenAIsliding window

Chat Event Counts

Reported by candidates from OpenAI's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live OpenAI OA. Under 2s to a working solution.
Founder's read

The edge case that sinks most people on this OpenAI problem is the window boundary. Chat Event Counts, reported in May 2026, asks you to count events for an exact (userId, chatId) pair in the last 15 minutes, and one off-by-one ruins the output. It looks like a string parsing warm-up. It's really a keyed sliding window over a stream of commands. Read the example carefully: at timestamp 16, the event at minute 0 is gone. If you blank on the window math, StealthCoder runs invisibly during the live OA as a safety net.

The problem

Complete the function below. The function receives the full standard input as a single string and returns the exact standard output lines for a chat-event tracker.
Problem Implement two operations for tracking chat events:
processEvent(userId, chatId, timestamp): record that userId had an event in chatId at timestamp.
getCount(userId, chatId, timestamp): return how many events for that exact (userId, chatId) pair occurred in the last 15 minutes, inclusive of the query timestamp and exclusive of events older than timestamp - 15 minutes.
In this command-based version, each line is either EVENT userId chatId timestamp or COUNT userId chatId timestamp. Return one output line for each COUNT command.

Function
solveChatEventCounts(input: String) → String[]
Complete solveChatEventCounts. It has one parameter, String input, containing newline-separated commands. Return the stdout payload as an array of lines, without trailing newline characters.

Examples
Example 1
input = "EVENT u1 c1 0\nEVENT u1 c1 10\nEVENT u1 c2 12\nCOUNT u1 c1 14\nCOUNT u1 c1 16\nEVENT u1 c1 20\nCOUNT u1 c1 25\nCOUNT u1 c2 25"
return = ["2","1","2","1"]
At timestamp 16, the event at minute 0 is older than 15 minutes and is not counted.

Constraints
Timestamps are integer minutes and commands are processed in input order.
Counts are keyed by both user id and chat id.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Parse each line, key a hash map by userId plus chatId, and store a list of timestamps per key. Since commands arrive in order, timestamps per key are non-decreasing. That means you can use a deque or a list with a start pointer and evict old events lazily, or binary search the list on each COUNT. The window is inclusive of timestamp minus 15 on the boundary side only if the event is not older than that, so keep events where t >= timestamp - 15. Check the example: at 16, the event at 0 is dropped because 0 < 1. The pitfall is keying only by user, or joining the ids without a separator so keys collide. Use a tuple or a delimiter. Another trap is emitting output for EVENT lines. Only COUNT produces a line. StealthCoder is the hedge if the boundary logic slips under pressure during the live OA.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Chat Event Counts cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass OpenAI's OA.

OpenAI reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Chat Event Counts FAQ

What's the trick in the OpenAI Chat Event Counts problem?+

Key a hash map by the (userId, chatId) pair and keep a timestamp list per key. On COUNT, count the events with t >= timestamp - 15 and t <= timestamp. Everything else is parsing and getting the boundary exactly right.

How hard is this one really?+

Easy to medium. The logic is short, but the boundary is where people lose points. Run your code against the example by hand, especially the query at 16 where the event at 0 must drop out.

Do I need a deque or is a plain list fine?+

Either works. A deque with eviction from the front gives amortized O(1) per command. A plain list with binary search for the cutoff also works. Pick whichever you can write without bugs under time pressure.

Should EVENT commands print anything?+

No. Only COUNT commands produce an output line. Collect results in an array and return it. Adding output for EVENT lines will break the expected result and fail every test.

How do I prepare in 48 hours for this kind of question?+

Practice a few keyed sliding window problems with timestamps and rehearse parsing lines into commands. Write the boundary condition on paper first. Test with the inclusive edge, an event exactly 15 minutes old, and different chats for the same user.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with OpenAI.

OA at OpenAI?
Invisible during screen share
Get it