RPC Timeout Monitor

Asked at GoogleOnsite

Reported by the problem's creator, not verified

A service writes a log record when a remote call starts and another when it ends. TimeoutMonitor(timeout) receives the records one at a time through add(call_id, timestamp, kind), where kind is "start" or "end". Timestamps never decrease, every call has one start record, and at most one end record that comes after it.

A call's running time is end - start once it has ended, and otherwise now - start, where now is the timestamp of the most recent record. A call has timed out when its running time is strictly greater than timeout.

Examples

  1. Example 1

    Input: init = [5], operations = [["add",[7,0,"start"]],["add",[8,2,"start"]],["add",[7,4,"end"]],["add",[9,5,"start"]],["timed_out",[]],["add",[8,10,"end"]],["timed_out",[]],["add",[9,12,"end"]],["timed_out",[]]]

    Output: [null,null,null,null,[],null,[8],null,[8,9]]

    Explanation: With timeout 5: call 8 runs from 2 to 10, which is 8 and so timed out. After its end record the answer is [8]. Call 9 runs from 5 to 12, which is 7, so the final answer is [8, 9]. Call 7 took 4 and never counts.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.