Exclusive Execution Time of Functions

Compute exclusive execution times for all functions in the program.

Statement

We are given an integer number nn, representing the number of functions running in a single-threaded CPU, and a list of strings, where each string represents the start or end timestamp of a specific function. Each function has a unique ID between 00 and n1n-1. Compute the exclusive time of the functions in the program.

Note: Exclusive time is the sum of the execution times for all the calls to a specific function.

Constraints

  • 11 <= n <= 100100
  • 11 <= logs.length <= 500500
  • 00 <= function_id < n
  • 00 <= timestamp <= 10910^9
  • No two start events and two end events will happen at the same timestamp.
  • Each function has an “end” log entry for each “start” log entry.

Example

Consider the following list of strings, where each string represents the ithi^{th} log entry formatted as:

{function_id}:{"start" | "end"}:{timestamp}

Each function is identified in the logs by a function ID:

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.