Grammarly Editor may have many asynchronous requests in flight at once. Implement an event processor that tracks each request in a map and marks it as completed, timed out, or still pending without scanning every active request for each event.
Each request has a unique identifier. A start event begins a request, and a resolve event represents its promise resolving. A request times out when it remains unresolved beyond timeout_ms. A resolution occurring exactly at its deadline succeeds.
Implement process_request_timeouts(events, timeout_ms, end_time).
events is a list of dictionaries sorted by nondecreasing time. Each dictionary has integer time, string type ("start" or "resolve"), and string id.timeout_ms, end_time, and event times are nonnegative integers."completed", "timed_out", or "pending".end_time, unresolved requests whose deadline is at or before end_time are timed out. Later deadlines remain pending.Use a hash map for active requests and a min-heap to find the next deadline efficiently.
def process_request_timeouts(events, timeout_ms, end_time):