Back to problems

Event Counting in a 15-Minute Sliding Window

Algorithm · OpenAI · Easy

Design an event counter that ingests a continuous stream of timestamped events and can report how many of them occurred during the latest 15 minutes (900 seconds). All timestamps are whole numbers of seconds. Calling record(t) logs a single event that happened at time t. Calling count(t) returns how many logged events have a timestamp inside the closed interval $$[t - 899, t]$$, with both endpoints included. The program reads a sequence of operations, each in one of two…

Loading the rest of the question…