109. Most Frequent Element
Core1000 ms256 MBSolved by 0%
Print the value that appears most often in the array, and how many times it appears, separated by a space.
If several values tie for most frequent, print the smallest of them.
Constraints - `1 ≤ n ≤ 200000` - `-1000000000 ≤ a[i] ≤ 1000000000`
Input
The first line contains an integer n.
The second line contains n space-separated integers.
Output
Print two integers on one line, separated by a single space, the most frequent value, then how often it appears. On a tie print the SMALLEST such value.
Input6
1 2 2 3 3 3
Output3 3
Notehas a clear winner
Input4
5 5 2 2
Output2 2
Notehas a tie, so the smaller value wins
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.
Hint 1Where to start
Hint 2The approachOpen hint 1 first. This one carries on from it.
Hint 3PseudocodeOpen hint 2 first. This one carries on from it.
Hint 4Full solutionOpen hint 3 first. This one carries on from it.