← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jul 2026

Summary

Uber SWE interview, coding round. One problem the whole time, stack-based simulation. Felt okay about my solution but the timestamp math tripped me up more than I expected.

Questions Asked (1)

Q1

Given execution logs from a single-threaded CPU running n functions, where each log entry records a function id, whether it started or ended, and a timestamp, compute the exclusive CPU time for each function (time the function itself ran, not counting time spent in functions it called).

Algorithms & Data Structures
Author's notes

My first instinct was right, use a stack to track which function is currently running.

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 function starts, push it onto the stack; when it ends, pop it and add the elapsed time to its exclusive time, then update the parent's start time to account for the child's execution. This ensures each function's exclusive time excludes time spent in nested calls.

Pro tip: Clarify that timestamps are inclusive and that the CPU is single-threaded, so no concurrency issues arise. Also, mention that you'll handle nested calls correctly by adjusting the parent's start time after a child completes.

1. Parse logs and initialize data structures

Convert each log entry into a tuple (id, type, timestamp) and initialize a stack to track active functions and a dictionary to accumulate exclusive times.

2. Process each log entry

Iterate through the logs: if it's a start, push the function id and timestamp onto the stack; if it's an end, pop the top, compute the elapsed time, add to the function's exclusive time, and update the new top's start time to the current timestamp + 1.

3. Handle nested calls correctly

When a function ends, ensure that the parent function's start time is adjusted to exclude the child's execution time, so the parent's exclusive time is accurate.

4. Return the result

After processing all logs, return the dictionary mapping function ids to their exclusive times, ensuring all functions are included even if they have zero exclusive time.

Key Points to Mention

  • Use a stack to manage nested function calls and track start times.
  • Exclusive time for a function = total time it was on top of the stack.
  • When a child function ends, update the parent's start time to avoid double-counting.
  • Timestamps are inclusive, so elapsed time = end - start + 1.
  • Single-threaded execution means no overlapping intervals, simplifying the logic.
  • Handle edge cases like multiple top-level functions and functions with no exclusive time.

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