Medium · System Design
Exclusive Time of Functions
Given n functions and a time-ordered list of logs 'id:start:t' and 'id:end:t' from a single-threaded CPU, where a start begins at the start of tick t and an end finishes at the end of tick t, return an array whose i-th value is the exclusive time of function i: the ticks it spent running, not counting the ticks of the calls it made.
Examples
Example 1
{
"n": 2,
"logs": ["0:start:0", "1:start:2", "1:end:5", "0:end:6"]
}Output: [3, 4]
Example 2
{
"n": 1,
"logs": ["0:start:0", "0:start:2", "0:end:5", "0:start:6", "0:end:6", "0:end:7"]
}Output: [8]
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.