My first instinct was just a plain stack with push on entry and pop on exit, which is correct but I spent too long explaining it before writing any code.
Start by clarifying the input format and requirements, then design a solution using a stack data structure to track function calls. Explain how to parse events, push on entry, pop on exit, and report the current stack. Discuss time and space complexity, and consider edge cases like mismatched events.
Pro tip: Mention that you would validate the trace for consistency (e.g., exit without matching entry) and discuss how this approach scales to large traces or real-time processing, showing awareness of production concerns.
Ask about the event format (e.g., JSON, CSV), whether events are well-formed, and what 'report' entails (e.g., print, return list). Confirm if multiple stacks or threads are involved.
Use a stack (LIFO) to maintain active calls. On entry, push the function name; on exit, pop. For reporting, return a copy of the stack or its size.
Check for exit events without matching entry (underflow) and entry events without exit (incomplete trace). Decide whether to ignore, log, or throw errors.
Each event is O(1) time; space is O(depth of stack). For large traces, consider streaming processing to avoid storing all events.
Mention how to handle multiple threads (separate stacks), recursion depth limits, or adding timestamps for profiling. Compare stack vs. tree representation.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.