← 返回 roblox 的题目列表Most Frequent Call Stack
类型:online_judge
Problem: Most Frequent Call Stack
You are given multiple sampled call stacks from a running program. Each call stack is a list of function names ordered from the entry function to the currently executing function, for example:
["main", "handleRequest", "queryDB"]
Two call stacks are considered identical if their entire function-name sequences are exactly the same.
Return the most frequent call stack and its frequency.
If multiple call stacks have the same maximum frequency, return the lexicographically smallest one. Lexicographical order is compared function by function.
Input Format
The first line contains an integer n, the number of call stacks.
The next n lines each describe one call stack:
m func1 func2 ... funcm
where m is the number of functions in the stack.
Output Format
Print two lines:
The first line contains the frequency of the most frequent call stack.
The second line contains the function names in that call stack, separated by spaces.
Constraints
1 <= n <= 10^5
1 <= m <= 100
The total number of function names across all stacks is at most 10^6
Function names contain only English letters, digits, and underscores
Each function name has length at most 50
Example 1
Input:
5
3 main auth check
3 main auth check
3 main feed render
2 main auth
3 main auth check
Output:
3
main auth check
Example 2
Input:
4
2 a b
2 a c
2 a b
2 a c
Output:
2
a b
Explanation: [a, b] and [a, c] both appear twice, so [a, b] is returned because it is lexicographically smaller.
Example
Input
5
3 main auth check
3 main auth check
3 main feed render
2 main auth
3 main auth check
Output
3
main auth check