← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Meta SWE interview with a stack-based simulation problem. Pretty standard coding round, nothing too wild, but the details matter more than they look.

Questions Asked (1)

Q1

Given logs of function calls on a single-threaded CPU, each log containing a function ID, whether it's a start or end event, and a timestamp, compute the exclusive execution time for each function (not counting time spent in functions it called).

Algorithms & Data Structures
Author's notes

The stack part clicked pretty fast for me but I fumbled the off-by-one on end timestamps for a bit.

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, and maintain a map from function ID to exclusive time. When an end event occurs, compute the total elapsed time for that function, subtract the time spent in any child functions (tracked via a separate stack or by adjusting the parent's start time), and add the exclusive time to the map.

Pro tip: Clarify whether timestamps are inclusive or exclusive and whether the log is guaranteed to be well-formed; handle edge cases like nested calls and multiple calls to the same function. Mention that you'd use a stack because it naturally models the call stack of a single-threaded CPU.

1. Parse and understand the log format

Identify the structure of each log entry: function ID, event type (start/end), and timestamp. Confirm assumptions about timestamp granularity and log validity.

2. Choose data structures

Use a stack to track active function calls (each entry stores function ID and start time) and a hash map to accumulate exclusive time per function ID.

3. Process events sequentially

For a start event, push the function and its start time onto the stack. For an end event, pop the top function, compute its total elapsed time, subtract the time spent in any nested calls (by adjusting the parent's start time), and add the exclusive time to the map.

4. Handle nested calls and time adjustment

When a function ends, update the parent function's start time to the current timestamp (or add the child's duration to the parent's start time) so that the parent's exclusive time excludes the child's execution.

5. Return the result

After processing all logs, output the map of function IDs to their exclusive execution times. Optionally, sort by function ID if required.

Key Points to Mention

  • Use a stack to simulate the call stack of a single-threaded CPU.
  • Maintain a hash map to accumulate exclusive time per function ID.
  • When a function ends, subtract the time spent in nested calls from its total elapsed time.
  • Adjust the parent function's start time to account for child execution time.
  • Handle edge cases: multiple calls to the same function, deeply nested calls, and invalid logs.
  • Time complexity is O(n) where n is the number of log entries; space complexity is O(m) where m is the maximum stack depth.

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