Search⌘ K
AI Features

Solution: Exclusive Time of Functions

Understand how to use a stack to calculate the exclusive time each function runs in a single-threaded CPU based on start and end logs. Explore how to handle nested function calls and manage execution time efficiently for 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 ...