Code Room
CodingMediumcod-g865
Subject ParsingLevel Mid–Senior~30 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.