← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Meta coding round, pretty standard algorithmic problem but the stack simulation tripped me up more than I expected for something that looks straightforward on paper.

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 (excluding time spent in nested calls).

Algorithms & Data Structures
Author's notes

Knew I needed a stack pretty quickly but fumbled the off-by-one stuff with the timestamps.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a stack to track the currently executing function and maintain a running total of exclusive time. When a start event occurs, add the elapsed time since the last event to the top function's exclusive time, then push the new function. When an end event occurs, add the elapsed time to the top function's exclusive time, pop it, and update the last timestamp.

Pro tip: Clarify whether timestamps are inclusive or exclusive and how nested calls are logged; this affects the off-by-one handling. Also, mention that the stack approach naturally handles arbitrary nesting depth.

1. Parse and Sort Logs

Ensure logs are sorted by timestamp. If not, sort them first. Parse each log into (function_id, event_type, timestamp).

2. Initialize Data Structures

Use a stack to keep track of active functions and a dictionary to accumulate exclusive time per function. Initialize last_timestamp to the first event's timestamp.

3. Process Events

Iterate through logs. For a start event, add (timestamp - last_timestamp) to the exclusive time of the function on top of the stack (if any), then push the new function. For an end event, add (timestamp - last_timestamp + 1) to the top function's exclusive time, pop it, and update last_timestamp.

4. Handle Timestamp Updates

After each event, set last_timestamp to the current timestamp. For end events, ensure the time slice includes the current timestamp (hence +1 if timestamps are inclusive).

5. Return Results

After processing all logs, return the dictionary mapping function IDs to their exclusive execution times.

Key Points to Mention

  • Stack-based approach to track nested function calls
  • Time accumulation logic: add elapsed time to the current top function before pushing/popping
  • Handling of inclusive vs exclusive timestamps (off-by-one adjustment)
  • Single-threaded assumption simplifies concurrency issues
  • Time complexity O(n) and space complexity O(n) where n is number of logs
  • Edge cases: empty logs, multiple top-level functions, deeply nested calls

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