Anthropic

Verified interview challenge

Aggregate exclusive profiler time

Calculate how much time each function spends executing its own work from a stream of nested call events.

Unlock with Full Access

The challenge

A single-threaded profiler records when calls start and end. Calls can nest, recur and appear more than once. Recover each function's exclusive execution time without counting the time spent inside its callees, then report the totals in the required order.

Exclusive time, not total duration
The result separates a function's own execution from the work performed by functions it calls.

What you'll practise

  • Nested call state

    Reconstruct which function is active as start and end events arrive.

  • Time accounting

    Assign intervals correctly through recursive calls, equal timestamps and idle periods.

  • Aggregating results

    Combine repeated function calls and produce a consistent ranking.

Your coding workspacePreview
solution.pyPython 3.13
def exclusive_profile_times(
    events
):
    # Your implementation goes here
    pass
Test cases

Run your code to see results.

Full instructions, starter code and test cases included with Full Access.