Problem Overview
"Exclusive Time of Functions" (LeetCode 636) involves calculating the exclusive execution time for n functions based on runtime logs. Each log entry follows the format "function_id:start/end:timestamp", with logs sorted by increasing timestamp. Exclusive time excludes time spent in nested child function calls.[1][9]
You are given an integer n, representing the number of functions labeled from 0 to n-1, and a list of logs where logs[i] represents events during the system's execution. Each log is a string in the format "function_id:start/end:timestamp", where function_id is an integer, start/end indicates if the function started or finished, and timestamp is an integer.
The logs are sorted by timestamp and no two logs share the same timestamp. Every function starts before it ends, and functions may be nested (a parent function pauses while a child executes).
Return an array of size n where ans[i] is the exclusive time for function i—the time it executed on the CPU excluding any child functions.[9][1]
Input: n = 2, logs = ["0:start:0","1:start:2","1:end:5","0:end:6"]
Output:[3][4]
Explanation:
Input: n = 1, logs = ["0:start:0","0:start:2","0:end:5","0:end:6"]
Output:[3]
Explanation: Function 0 runs exclusively from 0-2 and 5-6 (total 3 units); the nested call from 2-5 is its own execution but still counts as exclusive for the parent in this context—no, wait: actually, the second start is nested, so exclusive is only the non-nested parts: 0-2 and 5-6.[9]
Input: n = 2, logs = ["0:start:0","0:start:2","0:end:5","0:end:6"] (variant from sources)
Output: or adjusted based on nesting, but standard is wait—sources confirm similar to Ex1.[1][3]