Busiest Call Path
MediumHash Map ยท Roblox
Given events, a time-ordered log of function calls from several threads, return the call path that was entered most often.
Each entry is "<thread> enter <name>" or "<thread> exit <name>". Every thread has its own call stack, and an exit closes that thread's innermost open call. Calls may still be open when the log ends.
A call's path is the names of its thread's open calls, outermost first, joined with >. Each enter adds one to its path's count, across all threads. Break ties by more names, then by the smaller string. Return "" if there are no events.
Example 1
- Input:
- events = ["1 enter main", "1 enter parse", "1 exit parse", "1 enter parse", "1 exit parse", "1 exit main"]
- Output:
- "main>parse"
- Explanation
mainis entered once andmain>parsetwice.
Example 2
- Input:
- events = ["1 enter main", "2 enter main", "1 enter io", "2 enter db", "2 exit db", "2 enter db", "2 exit db", "1 exit io", "2 exit main", "1 exit main"]
- Output:
- "main>db"
- Explanation
mainandmain>dbare both entered twice; the longer path wins the tie.
Example 3
- Input:
- events = ["3 enter run", "3 enter run", "3 exit run", "3 exit run"]
- Output:
- "run>run"
Constraints
0 <= events.length <= 200000- Thread ids are non-negative integers written in decimal; names are 1 to 12 lowercase letters or
_. - Every
exitnames the innermost open call of its own thread.