← 返回 roblox 的题目列表Most Frequent Call Stack
类型:online_judge
Problem: Most Frequent Call Stack
You are given n sampled function call stacks. Each call stack is a sequence of function names ordered from the bottom of the stack to the top, for example:
main->render->draw
Two call stacks are considered identical only when their complete sequences of function names are identical and in the same order.
Return the call stack that occurs most frequently.
In the original version, any stack with maximum frequency may be returned.
Follow-up 1: add an explicit tie-breaking rule, such as returning the lexicographically smallest stack.
Follow-up 2: the input includes thread identifiers; compute the most frequent call stack separately for each thread.
Input Format
n
stack_1
stack_2
...
stack_n
n is the number of sampled call stacks.
Each stack_i is a non-empty string whose function names are separated by ->.
Output Format
Print the most frequent call stack. If multiple stacks have the same maximum frequency, print the lexicographically smallest one.
Constraints
1 <= n <= 200,000
The total length of all stack strings is at most 2 * 10^6.
Function names contain only letters, digits, and underscores.
Example
Input
5
main->render
main->render->draw
main->render
main->update
main->render
Output
main->render