Reported September 2026
Anthropicstack

Convert Stack Samples to Trace Events

Reported by candidates from Anthropic's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Anthropic OA. Under 2s to a working solution.
Founder's read

Anthropic reported this one in September 2026, and the detail that trips people is the last line of the spec: no end events after the final sample. The task is to turn profiler stack snapshots into start and end trace events. Compare each adjacent pair of stacks, find the common prefix, close what's gone, open what's new. It's a stack-style diff, not a hard algorithm. But the ordering rules are strict, and one off-by-one on the prefix check fails every test. If you blank on the OA, StealthCoder runs invisibly as a safety net and gives you the solution in real time.

The problem

A sampling profiler records the active call stack at several moments. You are given two parallel arrays:
timestamps[i] is the timestamp of sample i.
stacks[i] lists the active functions in sample i, from the outermost call to the innermost call.
Sample Transitions
Convert the samples into an ordered trace of function events.
For the first sample, emit a start event for every function from outermost to innermost.
Between adjacent samples, the longest common stack prefix remains active.
Emit end events for functions removed from the previous stack, from innermost to outermost.
Then emit start events for functions added by the current stack, from outermost to innermost.
Do not synthesize end events after the final sample. Any functions in the final sampled stack are still active.
Recursive calls at different stack depths are different active calls, even when they have the same function name.
Event Format
Return the events in order. Represent each event as [eventType, functionName], where eventType is "start" or "end".

Function
convertStackSamples(timestamps: int[], stacks: String[][]) → String[][]

Examples
Example 1
timestamps = [1,2,3]
stacks = [["main"],["main","f1","f2","f3"],["main"]]
return = [["start","main"],["start","f1"],["start","f2"],["start","f3"],["end","f3"],["end","f2"],["end","f1"]]
main starts with the first sample. The second sample starts f1, f2, and f3. The third sample removes those three calls, so they end from innermost to outermost. main remains active in the final sample, so no end event is emitted for it.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is the longest common prefix between the previous stack and the current one. Compare by position, not by name, because recursive calls at different depths are distinct calls even with the same function name. Walk both arrays with index i until the names differ or one ends. Then emit end events for the previous stack from the last index down to i, innermost first. Then emit start events for the current stack from i up to the end, outermost first. For the first sample, treat the previous stack as empty. Never emit ends after the final sample. The common pitfall is matching by name with a set, which breaks on recursion like [main, f, f]. Another is reversing the wrong half. If you freeze mid-OA, StealthCoder is the hedge that reads the statement and hands you the loop. The timestamps array is never used in the output.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Convert Stack Samples to Trace Events cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Anthropic's OA.

Anthropic reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Convert Stack Samples to Trace Events FAQ

How hard is Convert Stack Samples to Trace Events really?+

Easy to medium. There's no clever data structure. It's a prefix comparison between adjacent arrays plus careful event ordering. Most failures come from misreading the ordering rules or the no-final-ends rule, not from algorithm difficulty.

What's the trick to getting it right?+

Find the longest common prefix by index between the previous and current stack. Emit ends for previous[i..] in reverse, then starts for current[i..] in order. Start with an empty previous stack so the first sample emits starts for everything.

Do I need the timestamps array?+

No. The output only contains event type and function name. The timestamps are parallel data you can ignore. Don't sort or group by them, since the samples are already in order.

How do recursive calls affect the solution?+

They're why you compare by depth position. A stack like [main, f, f] has two separate active f calls. If the next stack is [main, f], the inner f ends and the outer f stays. A set or name lookup gets this wrong.

How do I prepare in 48 hours?+

Write this solution once from scratch, then test edge cases: identical consecutive stacks, empty stacks, full replacement, and recursion. Also do a few easy stack and array diff problems so prefix comparison feels automatic.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Anthropic.

OA at Anthropic?
Invisible during screen share
Get it