Search⌘ K
AI Features

Solution: Exclusive Time of Functions

Understand how to calculate the exclusive execution time of functions from logs in a single-threaded CPU environment. Learn to use stacks to track start and end events, manage nested or recursive calls, and correctly compute the execution times for each function. This lesson helps you implement an efficient solution to parse logs and calculate time with an O(m) time complexity.

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