Google VO Coding Interview / Online Assessment: Receives Log Entries and Detect Timed-Out RPCs

23 Views
No Comments

Imagine you have an RPC server that produces log entries and you’re analyzing it offline. There are two entries for each call: one when the RPC starts and one when the RPC finishes processing.

Your task is to efficiently determine if any RPC in the log timed out.

You can assume your function receives two arguments:

  • A timeout duration.
  • A collection of pre-parsed log entries, already sorted by timestamp.

To test your understanding, consider the following example:

Input timeout: 3

Input log:

| ID | Timestamp | Event Type |
|----|-----------|------------|
| 1  | 0         | Start      |
| 2  | 1         | Start      |
| 1  | 2         | End        |
| 3  | 6         | Start      |
| 2  | 7         | End        |
| 3  | 8         | End        |

Graphical representation of the log:

ID 1: [0, 2]
ID 2: [1, 7]
ID 3: [6, 8]

This problem asks you to inspect a time-ordered RPC log and determine whether any request exceeded a given timeout. Since each RPC has a Start and End entry, the standard approach is a single pass with a hash map that stores the start timestamp for each active ID. When the End entry appears, compute the elapsed time and compare it with the timeout. The solution is efficient, with linear time complexity and small auxiliary space.

END
 0