Code RoomFunction exclusive time
MediumPrep Room Coding #1428

Function exclusive time

CodingAlgorithms & data structuresMid–Senior~30 min

A single-threaded program runs `n` functions identified by ids `0..n-1`. You are given execution logs as strings `"{id}:{start|end}:{timestamp}"` in chronological order; a function may call others (nested) and may recurse. The exclusive time of a function is the total time spent in it not counting time spent in nested calls. `start` happens at the beginning of a timestamp and `end` at the end of a timestamp, so `0:start:0` then `0:end:0` is 1 unit. Return the exclusive time of each function, indexed by id.

Implement
exclusive_time(n: int, logs: list[str]) → list[int]
Examples
in[2,["0:start:0","1:start:2","1:end:5","0:end:6"]]out[3,4]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 30 min
InputExpectedGot
[2,["0:start:0","1:start:2","1:end:5","0:end:6"]][3,4]not run yetsample