Search⌘ K
AI Features

Solution: Exclusive Time of Functions

Explore how to calculate the exclusive execution time of multiple functions running on a single-threaded CPU by applying stack operations. This lesson helps you understand processing start and end logs for each function, managing nested function calls, and correctly computing execution times. You'll gain skills critical for solving interview questions involving function execution timing and stack utilization.

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 ...