← 返回 roblox 的题目列表Most Frequent Function Call Path
类型:online_judge
Most Frequent Function Call Path (Single Thread)
You are given function-call logs from a single-threaded program. Each log entry is one of:
START functionName: execution of functionName begins.
END functionName: execution of functionName ends.
The logs are valid: calls follow strict stack discipline, and every START has a matching END.
Whenever a START functionName event occurs, the sequence of functions on the current call stack, from the root function to functionName, is called a call path. For example, if the current stack is main -> parse -> tokenize, then the call path is main->parse->tokenize.
Return the most frequent call path, joining function names with ->.
If multiple paths have the same maximum frequency, return the lexicographically smallest path.
Input Format
The first line contains an integer N, the number of log entries.
The next N lines each contain either START functionName or END functionName.
Output Format
Print the most frequent call path.
Constraints
1 <= N <= 200,000
Function names contain only letters, digits, and underscores, with no spaces.
The log is valid and the call stack never underflows.
Example
Input:
8
START main
START parse
END parse
START parse
END parse
START render
END render
END main
Output:
main->parse
main->parse occurs twice, while every other path occurs once.
Example
Input
8
START main
START parse
END parse
START parse
END parse
START render
END render
END main
Output
main->parse