A turnstile logs the token value of every entry. It is guaranteed that one particular token value was used on strictly more than half of the entries. Print that dominant token value.
Line 1: an integer n, the number of entries.
Line 2: n space-separated integers, the token values in order.
A single integer: the token value that occurs on strictly more than n/2 of the entries.
Example 1
Input
5 2 2 1 2 3
Expected
2
Explanation
Token 2 appears 3 times out of 5, which is more than half, so 2 is the dominant token.
Example 2
Input
1 7
Expected
7
Explanation
A single entry: that token, 7, trivially forms the majority.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →