res
of length n
to store the exclusive time for each function, all initialized to 0.prev_time
to keep track of the start of the current interval.logs
list, and for each log entry:
a. Parse the log entry to extract the function ID, action (start or end), and timestamp.
b. If the action is 'start':
i. If the stack is not empty, update the exclusive time of the function at the top of the stack.
ii. Push the current function ID onto the stack.
iii. Update prev_time
to the current timestamp.
c. If the action is 'end':
i. Pop the function ID from the top of the stack.
ii. Update the exclusive time of the popped function.
iii. Update prev_time
to one plus the current timestamp (since the end time is inclusive).res
array containing the exclusive times.