A monitoring dashboard records n ping source IDs received during one time window. Determine whether a single source ID accounts for strictly more than half of all pings in the window (i.e. its count is greater than n / 2). At most one such ID can exist. If one exists, print it; otherwise print NONE.
Line 1: an integer n.
Line 2: n space-separated integers (the source IDs).
The dominant source ID (an integer) if one exists, otherwise NONE.
Example 1
Input
7 3 3 4 2 3 3 3
Expected
3
Explanation
ID 3 appears 5 times out of 7 pings, and 5 > 7/2 = 3.5, so 3 is the dominant source.
Example 2
Input
4 1 2 3 4
Expected
NONE
Explanation
Every ID appears only once, and 1 is not greater than 4/2 = 2, so no ID dominates. Output NONE.
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 →