Exclusive Time of Functions

Medium · Stack & Monotonic Stack · about 25 minutes

Asked at Meta, LinkedIn, Uber, Amazon, Google.

A single-threaded CPU runs n functions (ids 0..n-1). logs holds entries "id:start:t" (the function starts at the beginning of timestamp t) or "id:end:t" (it ends at the end of timestamp t). Functions can call each other (and themselves). A function's exclusive time is the time spent in it excluding the calls it makes. Return the exclusive time of each function.