FastPrepConvert Stack Samples to Trace Events
Problems/Convert Stack Samples to Trace Events

Convert Stack Samples to Trace Events

Anthropic logoAnthropic● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The reports clearly described converting sampled call stacks into ordered function start and end events, including recursive calls and inner-first endings. This practice version is an estimated 90% match for that core task; the original event class names and numeric constraints were not shared.

A sampling profiler is a tool that checks a running program at several moments. Each time, it records the call stack: the functions that are running right now. You get two arrays of the same length, and the same index in both describes the same sample:

  • timestamps[i] is the time of sample i.
  • stacks[i] lists the running functions in sample i, from the outermost call to the innermost call.

Sample Transitions

Turn the samples into an ordered list of function events.

  • For the first sample, add a start event for every function, from outermost to innermost.
  • For each later sample, compare its stack with the previous stack. Starting from the outermost call, find the longest run of calls that match position by position. Those calls are still running and get no events.
  • Add an end event for each call in the previous stack after that shared part, from innermost to outermost.
  • Then add a start event for each call in the current stack after that shared part, from outermost to innermost.

Do not add any end events after the last sample. Functions still in the last stack are still running.

A recursive call at a different depth in the stack is a different call, even when it has the same function name.

Event Format

Return the events in order. Each event is [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"]]

The first sample starts main. The second sample keeps main and adds f1, f2, and f3, so they start in that order. The third sample has only main again, so those three calls end, from innermost to outermost. main is still running in the last sample, so it never gets an end event.

Constraints

  • 1 <= timestamps.length <= 10^3
  • stacks.length == timestamps.length
  • 1 <= timestamps[i] <= 10^9
  • timestamps is strictly increasing, so the samples are given in time order.
  • 1 <= stacks[i].length <= 100
  • 1 <= stacks[i][j].length <= 20
  • Function names contain only lowercase English letters and digits.

More Anthropic interview questions

  • Fair Coin from a Biased CoinPHONE SCREEN · Seen Nov 2026
  • Crawl Same-Hostname URLs ConcurrentlyPHONE SCREEN · Seen Oct 2026
  • Confirmed Profiling Events with First-Observed StartsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Profiling Events from Consecutive Stack SamplesPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Find Duplicate File GroupsPHONE SCREEN · Seen Sep 2026
  • Longest-Match Tokenizer with Unknown SymbolsONSITE INTERVIEW · Seen Oct 2026
  • Recover a Function-Call LRU Cache with a Write-Ahead LogONSITE INTERVIEW · Seen Oct 2026
  • Trace Events from Stable Whole-Stack StatesONSITE INTERVIEW · Seen Oct 2026
  • Repair the Bootloader ProgramOA · ONSITE INTERVIEW · Seen Sep 2026
  • Cache Shared Image Pipeline PrefixesONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Generic Stack Operation SequenceArista Networks · PHONE SCREEN · ONSITE INTERVIEWArista Networks interview questions
  • Adjacent Pair and Run RemovalWhatNot · PHONE SCREEN · ONSITE INTERVIEWWhatNot interview questions
  • Asteroid CollisionSiemens · PHONE SCREEN
  • Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Exclusive Function TimeIllumio · PHONE SCREENIllumio interview questions
  • Multiline Text Editor with Cursor MovementDatologyAI · PHONE SCREEN
  • Run a Stack Language InterpreterJane Street · PHONE SCREENJane Street interview questions
  • Fountain SafetyGoogle · ONSITE INTERVIEWGoogle interview questions
  • Recipe Cart with Undo and RedoDecagon · PHONE SCREENDecagon interview questions

Anthropic interview experiences

  • Anthropic PR Review Round with Claude Code: 2 Experiences
All Anthropic interview questionsSee Anthropic hiring insights
Saved
class Solution {
    public String[][] convertStackSamples(int[] timestamps, String[][] stacks) {
      // write your code here
    }
}
Checking account…