← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jul 2026

Summary

Uber SWE coding round, got a stack-based simulation problem about tracking CPU function execution time. Pretty standard algorithmic question but the edge cases tripped me up a bit.

Questions Asked (1)

Q1

Given execution logs for n functions running on a single-threaded CPU, compute the exclusive time each function spends executing, not counting time spent in any nested calls.

Algorithms & Data Structures
Author's notes

My first instinct was to just iterate through logs and subtract child durations, but that falls apart fast with deeply nested calls.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a stack to track the currently executing function and its start time. When a new function starts, add the elapsed time since the last start to the exclusive time of the function on top of the stack, then push the new function. When a function ends, add the elapsed time including the current timestamp to its exclusive time, pop it, and update the start time for the next function on the stack.

Pro tip: Clarify whether the timestamps are inclusive or exclusive and handle the end timestamp carefully; off-by-one errors are common. Also, discuss how you would handle edge cases like nested calls and multiple calls to the same function.

1. Parse the logs

Extract the function ID, start/end indicator, and timestamp from each log entry. Ensure you understand the format and any constraints.

2. Initialize data structures

Create an array to store exclusive times for each function (indexed by ID) and a stack to keep track of the call stack. The stack will store pairs of (function ID, start time).

3. Process each log entry

For a start event: if the stack is not empty, add the time elapsed since the top's start time to the top function's exclusive time. Then push the new function with its start time. For an end event: add the time elapsed since the top's start time (including the current timestamp) to the top function's exclusive time, then pop the stack.

4. Handle time accounting correctly

When a function ends, the time from its start to the end timestamp is exclusive to it, but if there were nested calls, those were already subtracted when the nested calls ended. After popping, update the start time of the new top function to the current timestamp + 1 to avoid double-counting.

5. Return the result

After processing all logs, return the array of exclusive times for each function from 0 to n-1.

Key Points to Mention

  • Stack-based simulation of the call stack
  • Time accounting: exclusive time excludes nested calls
  • Handling of start and end events with timestamps
  • Off-by-one errors when dealing with inclusive timestamps
  • Updating the start time after popping to avoid double-counting
  • Time and space complexity: O(m) time and O(n) space where m is number of logs and n is number of functions

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.