← Decagon Interview Insights

Decagon·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Interviewed for a Software Engineer role at Decagon and got a classic stack-based CPU scheduling problem. Nothing too exotic but it required careful thinking about how timestamps work, especially the inclusive end semantics.

Questions Asked (1)

Q1

Given logs from a single-threaded CPU running n functions, where each log entry marks a function start or end with a timestamp, compute the exclusive execution time for each function (i.e., time in its own body, not counting time spent in callees).

Algorithms & Data Structures
Author's notes

The stack simulation part clicked pretty fast for me.

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 function starts, push it onto the stack; when it ends, pop it and add the elapsed time to its exclusive time, then subtract that elapsed time from the parent function's exclusive time if the stack is not empty.

Pro tip: Clarify the timestamp semantics upfront: whether the end timestamp is inclusive or exclusive, and whether the start and end timestamps are in the same unit. This avoids off-by-one errors and shows attention to detail.

1. Clarify log format and timestamp semantics

Ask whether timestamps are integers, whether the end timestamp is inclusive, and if there are any edge cases like nested calls or multiple top-level functions.

2. Choose a stack-based approach

Use a stack to maintain the call hierarchy. Each stack frame stores the function ID and the start time (or last resume time) of that function.

3. Process each log entry

For a start event, push the function and its start time onto the stack. For an end event, pop the function, compute its exclusive time as (end_time - start_time + 1) if inclusive, add to its total, and update the parent's start time to end_time + 1.

4. Handle nested calls and parent time adjustment

When a function ends, if the stack is not empty, the parent's exclusive time should exclude the child's execution time. This is naturally handled by updating the parent's start time to the child's end time + 1.

5. Return results in order

Collect exclusive times for each function ID, ensuring the output is in the order of function IDs (e.g., 0 to n-1).

Key Points to Mention

  • Stack data structure to track call hierarchy
  • Timestamp inclusivity and off-by-one handling
  • Updating parent function's start time after child completes
  • Time complexity O(m) where m is number of log entries
  • Space complexity O(n) for stack and result array
  • Edge cases: multiple top-level functions, deeply nested calls, zero-duration functions

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