← 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 CPU scheduling / call stack problem. Nothing too wild but it required you to actually think through the edge cases carefully.

Questions Asked (1)

Q1

Given a list of log strings in the format '{function_id}:{start|end}:{timestamp}' for n functions running on a single-threaded CPU, compute the exclusive execution time for each function (i.e. time on CPU excluding any time spent inside nested calls).

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 the timestamp when it last resumed. When an 'end' event occurs, compute the function's exclusive time by subtracting the time spent in nested calls, then update the parent's exclusive time accordingly.

Pro tip: Clarify that timestamps are inclusive of both start and end moments, and that the CPU is single-threaded so events are strictly nested. This avoids off-by-one errors and shows attention to detail.

1. Parse and Sort Logs

Parse each log string into function ID, event type, and timestamp. Ensure logs are processed in chronological order; if not already sorted, sort them by timestamp.

2. Initialize Stack and Result Map

Create a stack to track active function calls and a map to accumulate exclusive time per function ID. The stack will store pairs of (function ID, start timestamp of current exclusive segment).

3. Process Events with Stack

For a 'start' event: if the stack is not empty, add the time elapsed since the parent's last resume to the parent's exclusive time. Then push the new function with its start timestamp. For an 'end' event: pop the function, add the time from its start to the current timestamp (inclusive) to its exclusive time, and if the stack is not empty, update the parent's start timestamp to current timestamp + 1.

4. Handle Timestamp Inclusivity

Account for the fact that both start and end timestamps are inclusive. When a function ends, its exclusive time includes the end timestamp, so duration = end - start + 1. When resuming a parent, its next segment starts at end + 1.

5. Return Results

After processing all logs, return the map of function IDs to their exclusive execution times. Ensure all functions that started also ended (valid input).

Key Points to Mention

  • Stack-based approach to handle nested function calls
  • Time complexity: O(n) where n is number of log entries, assuming logs are sorted or sorting takes O(n log n)
  • Space complexity: O(n) for stack and result map
  • Handling inclusive timestamps correctly to avoid off-by-one errors
  • Updating parent's exclusive time when child function starts or ends
  • Edge cases: single function, deeply nested calls, multiple sequential calls

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