AO
Back

Most Frequent Call Stack / Call Path Analysis

CodingOnsiteLast reported October 2026High Frequency

Problem Overview

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

  • Up to 100,000 lines; call depth at most 1,000
  • A line starts with -> or <-, usually followed by a space; one report writes ->A with no space, and the tests use both
  • Logs are well-formed: every exit matches the function on top of the stack
  • No recursion: the same name never sits on the stack twice at once

Follow-up Arc

Interviewers escalate through these phases. The order varies, but most candidates see at least one from each bucket.
Concurrency · 1Trade-off discussion · 2
Concurrency

Can 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))

Trade-off discussion

What if multiple call paths share the same highest frequency? Which one should be returned?

Probes for: After solving the base single-threaded version

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.

Probes for: After solving tie-breaking

Approach Trade-offs

Approaches actually attempted in reports — including ones that lost candidates time. Pick deliberately.
ApproachNotes
Plain counter of function namesTwo 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.

What Reports Emphasize

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.

Practice

Write your own against 15 test cases, or read the worked solution — approach, complexity, and code that runs.
Did this match your interview?

If you have had this round, tell us how close this page was. It is how we keep the pages accurate.

Prepping for Roblox with friends?

Send them this page. It is free to read, no account needed.

More Roblox Questions

Free preview

Every question in the Roblox catalog gets this depth

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.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Roblox · Coding · Reported 21× across candidate reports
Is this helpful?