Imagine you're monitoring a single-threaded CPU that executes a program containing n functions. Each function has a unique ID from 0 to n-1, and function calls follow a stack-based execution model - when a function starts, it's pushed onto the call stack, and when it ends, it's popped off.
You're given execution logs in the format "function_id:start:timestamp" or "function_id:end:timestamp". For example:
"0:start:3"means function 0 started at the beginning of timestamp 3"1:end:2"means function 1 ended at the end of timestamp 2
Your task: Calculate the exclusive execution time for each function. This means the total time each function spent actually executing (not waiting for other functions to complete).
Key insight: When a function calls another function, the caller's execution is paused until the callee returns. You need to track which function is actively running at each moment.
Input & Output
Constraints
- 1 โค n โค 100
- 1 โค logs.length โค 500
- 0 โค function_id < n
- All function calls are properly nested and matched
- 0 โค timestamp โค 109