Profiling Events from Consecutive Stack Samples
Reported by candidates from Anthropic's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt at this Anthropic OA, reported in September 2026, is tracking function names instead of full stack prefixes. Recursive calls like a -> a collapse into one call and your output goes wrong on example 2. The task is to turn consecutive stack samples into start and end events, with an n-consecutive confirmation rule. It's a run-length tracking problem over prefixes, a sliding-window flavor. If you blank during the live assessment, StealthCoder runs invisibly as a safety net and reads the problem for you. Know the trick first, though, and you probably won't need it.
The problem
Related interpretation: Confirmed Profiling Events with First-Observed Starts uses the same confirmation rule but stores the first observation in the successful run as the start timestamp. A sampling profiler records the active call stack at strictly increasing timestamps. You are given parallel arrays: timestamps[i] is the time of sample i. stacks[i] lists active function names from outermost to innermost. A call is identified by its full stack prefix, so recursive calls with the same function name at different depths are distinct calls. Confirmation Rule A call becomes confirmed after its exact stack prefix appears in n consecutive samples. When it first becomes confirmed, emit ["start", confirmationTimestamp, functionName], using the timestamp of the nth consecutive sample. If a confirmed call is absent from a later sample, emit ["end", currentTimestamp, functionName]. At one timestamp, emit endings from innermost to outermost before emitting newly confirmed starts from outermost to innermost. A call that disappears before reaching n samples emits no events. Do not synthesize end events after the final sample; calls in the final sampled stack remain active. Output Format Return all events in order as strings. Convert each integer timestamp to its decimal string representation. Function generateProfilingEvents(timestamps: int[], stacks: String[][], n: int) → String[][] Examples Example 1 timestamps = [10,20,30,40,50] stacks = [["main"],["main","parse"],["main","parse"],["main"],["main"]] n = 2 return = [["start","20","main"],["start","30","parse"],["end","40","parse"]] main is confirmed at timestamp 20. parse is confirmed at 30 and ends when it is absent at 40. No final end is synthesized for main. Example 2 timestamps = [1,2,3,4,5,6] stacks = [["a"],["a","a"],["a","a"],["a","tmp"],["a","b"],["a","b"]] n = 2 return = [["start","2","a"],["start","3","a"],["end","4","a"],["start","6","b"]] The outer and recursive a calls confirm separately at timestamps 2 and 3. The recursive call ends at 4. tmp appears only once and is suppressed, while b confirms at 6. Constraints 1 <= timestamps.length == stacks.length <= 1000 1 <= n <= timestamps.length Timestamps are strictly increasing signed 32-bit integers. 0 <= stacks[i].length <= 100 Every function name is non-empty.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Treat each call as its prefix: stack[0..d]. For every sample, build the set of prefixes at each depth. Keep a map from prefix (join with a separator that can't appear in names, or use a tuple/list key) to its consecutive count and a confirmed flag. When a prefix is present, increment its count. When absent, delete it, and if it was confirmed, queue an end event. At each timestamp, emit ends innermost to outermost (deepest prefix first), then starts outermost to innermost for prefixes whose count just hit n. The pitfall is ordering and the n=1 case, where a call confirms the moment it appears. Another trap is a prefix vanishing when a parent changes: child prefixes differ, so they end too. Never emit ends after the last sample. Complexity is O(total stack length) per sample, fine for 1000 by 100. If the live OA scrambles your ordering logic, StealthCoder is the hedge.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Profiling Events from Consecutive Stack Samples 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. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Anthropic's OA.
Anthropic reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Profiling Events from Consecutive Stack Samples FAQ
What's the trick in the Anthropic profiling events problem?+
Identify a call by its full prefix, not its function name. That makes recursive calls distinct and handles parents changing. Track a consecutive count per prefix, confirm at n, and drop the entry the moment it's missing from a sample.
How do I get the event ordering right?+
At each timestamp, first emit ends for confirmed prefixes that disappeared, sorted deepest to shallowest. Then emit starts for prefixes hitting count n, shallowest to deepest. Build both lists per sample, sort by depth, then append. Don't interleave them.
What happens when n equals 1?+
Every prefix confirms on its first appearance, so it emits a start immediately at that timestamp. Nothing is suppressed. Your count logic handles it naturally if you check count == n right after incrementing, so don't special-case anything.
Do I emit end events for calls still active at the end?+
No. The problem says not to synthesize ends after the final sample. Calls in the last stack stay active. Only emit an end when a confirmed call is absent from a later sample, like parse at timestamp 40 in example 1.
How do I prepare for this in 48 hours?+
Hand-trace example 2 until the recursive a case makes sense. Then code it with a dictionary keyed by prefix tuples, and test n=1, empty stacks, and a call that reappears after a gap. A reappearing call must restart its count from 1.