← Uber Interview Insights

Uber·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Uber technical screen with a classic stack-based problem. Nothing too wild but it took me longer than I'd like to admit to get the logic right.

Questions Asked (1)

Q1

Given a list of log messages representing function start and end events on a single-threaded CPU, compute the exclusive execution time for each function by its ID.

Algorithms & Data Structures
Author's notes

The tricky part isn't the stack mechanics, it's remembering to handle the timestamp math correctly when a function resumes after a nested call returns.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a stack to track the currently executing function and a timestamp of when it last started or resumed. When a function ends, compute its exclusive time by subtracting the time spent in nested calls, and update the parent's accumulated time accordingly.

Pro tip: Clarify the log format and timestamp semantics upfront (e.g., whether end timestamps are inclusive) to avoid off-by-one errors, and mention that the stack approach naturally handles nested calls.

1. Parse and Initialize

Parse each log entry into function ID, event type (start/end), and timestamp. Initialize a stack to track active functions and a map to store exclusive times.

2. Process Start Events

On a start event, if the stack is not empty, add the time elapsed since the last event to the exclusive time of the function at the top of the stack. Then push the new function ID onto the stack and update the last timestamp.

3. Process End Events

On an end event, pop the function ID from the stack, add the time elapsed since the last event (inclusive of the end timestamp) to its exclusive time, and update the last timestamp to the end timestamp + 1.

4. Handle Nested Calls

Ensure that time spent in nested functions is correctly subtracted from the parent's exclusive time by updating the parent's time when a child starts or ends.

5. Return Result

After processing all logs, return the map of function IDs to their exclusive execution times.

Key Points to Mention

  • Stack data structure for tracking function call hierarchy
  • Timestamp handling and off-by-one errors (inclusive vs exclusive end times)
  • Accumulating exclusive time by subtracting nested call durations
  • Single-threaded assumption simplifies concurrency issues
  • Time complexity O(n) where n is number of log entries
  • Space complexity O(d) where d is maximum call stack depth

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