Search⌘ K
AI Features

Exclusive Time of Functions

Explore how to compute the exclusive time of functions running on a single-threaded CPU using stack data structures. Learn to interpret execution logs with start and end timestamps, handle function preemption, and implement a solution to determine total runtime per function. This lesson builds your skills in analyzing complex timing problems common in coding interviews.

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 00 and n1n-1. 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 ...