We’re preparing your current view and syncing the latest data.
Given the number of functions n and a list of logs where each log is a string representing a function start or end event with timestamps, compute the exclusive time of each function. The exclusive time of a function is the sum of execution times for that function excluding the time spent by calling other functions (i.e., nested calls). The CPU is single-threaded and processes functions in a depth-first manner, meaning a function can be paused to call another function and then resumed later when the called function completes.
An integer n representing the number of functions, and an array of strings logs representing function call logs. Each log is formatted as: "function_id:start_or_end:timestamp".
Return a list of integers where the ith element is the exclusive time of the function with id i.
1 <= n <= 100 1 <= logs.length <= 500 0 <= function_id < n 0 <= timestamp <= 10^9 logs are sorted by timestamp
Example 1
Input
n = 2 logs = ["0:start:0","1:start:2","1:end:5","0:end:6"]
Output
[3,4]
Explanation
Function 0 starts at 0, runs until 2 when function 1 starts, so function 0 runs exclusively for 2 units initially. Function 1 runs from 2 to 5 inclusive (4 units). Function 0 resumes after function 1 ends at 5 and ends at 6, adding 1 more unit. Total exclusive times: function 0 = 3, function 1 = 4.