Exclusive Time of Functions
Explore how to compute the exclusive time each function runs in a single-threaded CPU by analyzing execution logs. Understand how to use stack-based algorithms to track function start and end times, handle preemptions, and accurately sum exclusive execution durations. This lesson deepens your comprehension of stack applications in timing-related coding problems, preparing you to solve similar coding interview challenges with confidence.
We'll cover the following...
Statement
We are given an integer number, n, representing the number of functions running in a single-threaded CPU, and an execution log, which is essentially a list of strings. Each string has the format {function id}:{"start" | "end"}:{timestamp}, indicating that the function with function id either started or stopped execution at the time identified by the timestamp value. Each function has a unique ID between and . Compute the exclusive time of the functions in the program.
Note: The exclusive time is the sum of the execution times for all the calls to a ...