Level: Senior-Level
Round: Full Journey · Type: Coding · Difficulty: 7/10 · Duration: 60 min · Interviewer: Neutral
Topics: Data Structures, Algorithms, Call Chain Analysis
Location: San Francisco Bay Area
Interview date: 2026-01-20
I was asked the following coding question:
A software system logs its execution traces as a sequence of program events, where each event records either a function call or a function return. Each entry in the input list traces is one of:
"-> function_name": indicates that function_name has been called and is added to the call chain."<- function_name": indicates that function_name has returned and is removed from the top of the call chain.At any point, the call chain represents the list of active function calls, ordered from the first called (bottom) to the most recent (top). Every time a function is called (i.e., for every "-> function_name" in traces), record the current call chain immediately after the call.
Your task is to find the most frequently occurring call chain across the execution. The call chain should be output as a list of function names, from first called to last called, joined by "->".
If multiple call chains appear with the same maximum frequency, return the one with the greatest depth (most functions on the chain). And the result is guaranteed to be unique after applying these rules.
Return a string array of length 2, where:
Constraints:
`
Example 1:
Input: traces = ["-> main", "-> onButtonPress", "-> validateUserInput", "<- validateUserInput", "-> validateUserInput", "<- validateUserInput", "<- onButtonPress", "-> onKeyboardInput", "<- onKeyboardInput", "<- main"]
Output: [
"main -> onButtonPress -> validateUserInput", "2"]
Explanation: The function call traces are shown below:
-> main -> onButtonPress -> validateUserInput <- validateUserInput -> validateUserInput <- validateUserInput <- onButtonPress -> onKeyboardInput <- onKeyboardInput <- main
The call chain "main -> onButtonPress -> validateUserInput" appears twice, which is more than any other call chains.
Example 2:
Input: traces = ["-> func1", "-> func2", "<- func2", "-> func2", "<- func2", "<- func1"]
Output: ["func1 -> func2", "2"]
Example 3:
Input: traces = ["-> level1", "-> level2", "-> level3", "-> level4", "<- level4", "<- level3", "<- level2", "-> level2", "-> level3", "-> level4", "<- level4", "<- level3", "<- level2", "<- level1"]
Output: ["level1 -> level2 -> level3 -> level4", "2"]