Interview Experience
Roblox · Software Engineer
I was asked to write code that parses a stack trace log and uses a stack to count call occurrences. I also needed to parse call and return statements. The coding problem was: You’re given a sequence of logs representing function entries and exits in a single-threaded program. Each entry is of the form `"-> funcName"` and each exit is `"<- funcName"`. When a function is entered, the current full call path is the `->`-joined list of functions on the stack (top included). For example, if the current call stack is `[main, handleEvents, handleClickEvent]`, the path is: ``` main->handleEvents->handleClickEvent ``` Your task is to count how many times each full call path occurs (on every `->` event) and return the path with the highest frequency. 🧠 Tie-Breaking Rules If multiple paths share the same highest frequency: 1. Prefer the deeper path (one with more functions). 2. If depth is also tied, prefer the one that appeared first while scanning the logs (left-to-right). If the input is empty, return an empty string. 📘 Example 1 Input ``` ["-> main", "-> handleEvents", "-> handleClickEvent", "<- handleClickEvent", "-> handleClickEvent", "<- handleClickEvent", "<- handleEvents", "<- main"] ``` Counting (on each entry): - `main` → 1 - `main->handleEvents` → 1 - `main->handleEvents->handleClickEvent` → 2 Output ``` "main->handleEvents->handleClickEvent" ``` 📘 Example 2 Input ``` ["-> main", "-> handleEvents", "-> handleKeyEvent", "<- handleKeyEvent", "-> handleClickEvent", "<- handleClickEvent", "-> handleClickEvent", "<- handleClickEvent", "-> handleKeyEvent", "<- handleKeyEvent", "<- handleEvents", "<- main"] ``` Here both `main->handleEvents->handleClickEvent` and `main->handleEvents->handleKeyEvent` occur twice. We choose the click path because it reached the top frequency first. Output ``` "main->handleEvents->handleClickEvent" ``` 📘 Example 3 Input ``` [] ``` Output ``` "" ``` ⚙️ Constraints - `0 ≤ len(traces) ≤ 100,000` - Each log line starts with either `"-> "` or `"<- "`. - `funcName` contains only letters, digits, or underscores. - Logs are well-formed — every exit matches a previous entry. - No recursive calls (the same function will not be re-entered before it returns). - The call depth will not exceed 1,000. - Total distinct paths ≤ total entries.