Most Frequent Call Path in Interleaved Logs
Updated
Problem statement
You are given a time-ordered array logs containing function-call events from multiple threads. Every event has one of these forms:
threadId|ENTER|functionName: pushfunctionNameonto that thread's call stack.threadId|RETURN|functionName:functionNameis the current top frame of that thread, so pop it.
Process the events in input order. Immediately after applying each event, if that event's thread has a non-empty stack, observe its complete active call path from the root frame to the current frame. Serialize a path by joining its function names with >.
Count equal path strings across all threads and all observations. Return the path with the greatest count. If several paths have the same greatest count, return the lexicographically smallest path.
Function
mostFrequentCallPath(logs: String[]) → StringExamples
Example 1
logs = ["t1|ENTER|main","t1|ENTER|load","t1|RETURN|load","t1|RETURN|main"]return = "main"The observed non-empty paths are main, main>load, and main. Therefore main occurs twice.
Example 2
logs = ["t1|ENTER|api","t2|ENTER|worker","t1|ENTER|parse","t2|ENTER|parse","t1|RETURN|parse","t2|RETURN|parse","t1|RETURN|api","t2|RETURN|worker"]return = "api"Paths api and worker each occur twice. The other two paths occur once, so the lexicographically smaller tied winner is api.
Example 3
logs = ["a|ENTER|root","b|ENTER|root","a|ENTER|x","b|ENTER|x","a|RETURN|x","b|RETURN|x","a|RETURN|root","b|RETURN|root"]return = "root"Identical paths observed on different threads share one global frequency. Path root is observed four times, while root>x is observed twice.
Constraints
2 <= logs.length <= 200000.- Every
threadIdandfunctionNameis a non-empty case-sensitive string of letters, digits, or underscores. - Every return event matches the current top frame of its thread.
- Every thread begins with an entry event and has a balanced call stack after the final event.
- The total length of all event strings is at most
2 * 10^6.
More Roblox Onsite Interview questions
- Most Frequent Call Path From Function Trace LogsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Candy Crush Grid Matching and GravityPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Topological Sort with Secondary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Most Frequent Call Stack Per ThreadPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Count and Score Distinct Hat AssignmentsONSITE INTERVIEW · Seen Sep 2026
- Rate Limiter Sliding Window With Per-Entity LimitsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Grid Pathfinding with Obstacles (DFS)PHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
- Maximize Distance to Closest Person — Return the SeatONSITE INTERVIEW · Seen Jun 2026
- Sliding Window: Target Containment and Most-Repeated WindowONSITE INTERVIEW · Seen Jun 2026
Similar questions at other companies
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Trace Events from Stable Whole-Stack StatesAnthropic · ONSITE INTERVIEWAnthropic interview questions
- Render a Comment HierarchyAmazon · ONSITE INTERVIEW
- Project and Filter Structured RecordsStripe · PHONE SCREENStripe interview questions
- Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
- Cheating CodemakerJane Street · OAJane Street interview questions
- Credit Card Command ProcessorChime · PHONE SCREEN
- Project JSON Fields into a Target FormatBooking.com · PHONE SCREEN
- Compare Character Arrays with BackspacesOdoo · OAOdoo interview questions
Roblox interview experiences
- Roblox OA: What It Tests (2026)
- Roblox New Grad Early OA Tasks: 10 Experiences (Part 7 of 7)
- Roblox New Grad Engineer Rounds: 13 Experiences (Part 6 of 7)
- Roblox New Grad HackerRank OA: 18 Experiences (Part 5 of 7)
- Roblox New Grad CodeSignal Finals: 23 Experiences (Part 4 of 7)
- Roblox New Grad Games and BQ: 25 Experiences (Part 3 of 7)