def most_frequent_call_path(logs):
A program writes a trace line every time a function is entered or returns. -> funcName means the function was entered; <- funcName means it returned. When a function is entered, the current full call path is every function then on the stack, outermost first, joined by ->. Reports describe three sequential parts (in one, each part's tests had to be run and submitted before the next opened), and several say the clock is tight.
Part 1 — Most frequent call path
Implement most_frequent_call_path(logs) -> str. Count each full call path once per entry event and return the path with the highest count, joined by ->. For an empty list return "". If several paths share the highest count, return the one that reached that count first while scanning left to right.
logs = [
"-> 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".
Constraints
-> or <-, usually followed by a space; one report writes ->A with no space, and the tests use bothReports describe the second part as a tie-break on top of the count: when two paths have the same count, the deeper one wins ('break by max depth when tie'; 'return the deeper one, just change the comparison'). On equal depth too, one posted prompt's worked example and a reply pick the path that reached the count first, while other reports say the first one seen. One reader asked whether depth overrides the count; the reports describe it only as a tie-break.
The log lines now carry a thread id and are interleaved. Reports describe returning each thread's own most frequent path, and one says to return the Part 2 result per thread. One candidate added a dict keyed by thread. Group the lines by thread (or keep a stack and counter per thread) and apply the same rules to each; the input only carries thread ids, so no concurrent code is involved (our reading: no report asks for it).
One candidate reports the interviewer asked them to call the function they had already written for the per-thread part, and notes that the reports they had read described each follow-up written separately. Group the lines by thread id and call the earlier function on each group.
This question is reported as a three-part round: most frequent call path, then a depth tie-break, then one answer per thread. It shows up both as a phone screen and as an onsite coding round. Several reports say time is tight; one advises finishing the first two parts fast, another says a slow write-up fails, and one candidate ran out of time halfway through the per-thread part.
In one report each part had its own test cases to run and submit before the next part opened, and the interviewer pointed out small bugs along the way. In another, each follow-up opened in a new pane with the previous code still there, to be edited in place. On this page each part starts from its own skeleton, so bring your previous function along. Candidates in two reports say the log parsing is where the small bugs come from.
The one written prompt a candidate posted states the tie-break rule as "appeared first" but resolves its own example by "reached that frequency first"; a reply describing the same round uses the second wording, and other reports just say "the first one". Settle this with the interviewer before coding.
Outcomes are mixed. Three candidates report offers after loops that included this round, and one passed the phone screen with it. Others report rejections: one after finishing all three parts with every test passing, one who only finished the base question, and one who was told the per-thread part would not count and later heard from the recruiter that it was not done. Another interviewer also called Part 3 optional. Do not skip it.
A program writes a trace line every time a function is entered or returns. -> funcName means the function was entered; <- funcName means it returned. When a function is entered, the current full call path is every function then on the stack, outermost first, joined by ->. Reports describe three sequential parts (in one, each part's tests had to be run and submitted before the next opened), and several say the clock is tight.
Part 1 — Most frequent call path
Implement most_frequent_call_path(logs) -> str. Count each full call path once per entry event and return the path with the highest count, joined by ->. For an empty list return "". If several paths share the highest count, return the one that reached that count first while scanning left to right.
logs = [
"-> 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".
Part 2 — Deeper path wins a tie
Change the tie rule of most_frequent_call_path(logs) -> str. Count still decides first. If several paths share the highest count, the deeper path (more functions) wins. If the depth is also tied, the path that reached that count first wins.
logs = [
"-> main", "-> handleEvents",
"-> handleKeyEvent", "<- handleKeyEvent",
"-> handleClickEvent", "<- handleClickEvent",
"-> handleClickEvent", "<- handleClickEvent",
"-> handleKeyEvent", "<- handleKeyEvent",
"<- handleEvents", "<- main",
]
The click path and the key path both occur twice at depth 3. The key path appears first, but the click path reaches 2 first, so the output is "main->handleEvents->handleClickEvent".
Part 3 — One answer per thread
Implement most_frequent_call_path_per_thread(logs) -> dict. Each item of logs is now a (thread_id, line) pair, and lines from different threads are interleaved. Every thread has its own call stack. Return {thread_id: path} with one entry per thread, where each path follows the Part 2 rules applied to that thread's lines alone. Reuse your Part 2 function. The input only carries a thread id; no concurrent code is needed. An empty list returns {}.
logs = [(1, "-> a"), (2, "-> x"), (1, "-> b"), (2, "<- x"), (1, "<- b"), (1, "<- a")]
# -> {1: "a->b", 2: "x"}
Constraints
-> or <-, usually followed by a space; one report writes ->A with no space, and the tests use bothCan you implement the multi-threaded version by reusing your existing single-thread function rather than rewriting logic? (when: During the multi-thread part (one report))
What if multiple call paths share the same highest frequency? Which one should be returned?
Now the input logs come from multiple threads and are interleaved. Each log entry includes a thread_id. Return the most frequent call path for each thread separately.
| Approach | Notes |
|---|---|
| Plain counter of function names | Two replies suggest a plain counter with no stack. That answers only the phone-screen variant that asks which function name is called most often; the call-path version needs the stack to know each entry's full path. |
Common mistakes: One candidate spent a long time reading the prompt, finished only the base question, and was rejected.; Two candidates say the log parsing is where small bugs creep in. Our recommendation: check the prefix handling ('-> name' and '->name') and that the path includes the function just entered.; Skipping the per-thread part: one candidate was told it would not count, talked through it instead, and the recruiter's feedback was that it was not done. Another interviewer also called it optional.; Finishing is not always enough: one candidate completed all three parts with every test passing and was still rejected two days later; another reply in a different thread reports the same.
Interviewer hints: One interviewer told the candidate to reuse the function already written for the per-thread part.; One interviewer pointed out small bugs during the session; the candidate, interviewing at senior level, was unsure whether that counted against them.
What passers do: Reports advise speed: one says to finish the first two parts quickly because time is short, another says a slow write-up fails.; Reported approach: a stack for the current path and a counter keyed by the path, counted on entry lines.; One candidate who received an offer handled the interleaved multi-thread part by adding a dict keyed by thread.; One interviewer asked the candidate to reuse the function already written for the per-thread part.; In one report each part had test cases to run and submit before the next part opened; in another, each follow-up opened in a new pane with the previous code kept.
If you have had this round, tell us how close this page was. It is how we keep the pages accurate.
Send them this page. It is free to read, no account needed.
What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 37 Roblox questions, refreshed monthly from new candidate reports.