Astronomers tracking a meteor shower log the integer magnitude rating of every meteor they observe, in the order it streaked overhead. Meteors whose magnitude rating is even are classified by the observatory as "silver streak" events. The team wants to know which even magnitude rating occurred most often across the whole night's log. If two or more even magnitudes are tied for the highest count, report the smallest of them. If not a single logged meteor has an even magnitude, report -1 instead.
The first line contains a single integer n, the number of logged meteors. The second line contains n space-separated integers, the magnitude rating of each meteor in the order it was recorded.
Print a single integer: the even magnitude rating with the highest count (ties broken by the smaller value), or -1 if the log contains no even magnitude rating.
Example 1
Input
7 0 1 2 2 4 4 1
Expected
2
Explanation
Even magnitudes logged are 0 (once), 2 (twice), and 4 (twice); the odd magnitude 1 (twice) doesn't count. The highest even count is 2, tied between 2 and 4, so the smaller value 2 is reported.
Example 2
Input
6 4 4 4 9 2 4
Expected
4
Explanation
Even magnitudes logged are 4 (four times) and 2 (once); 9 is odd and ignored. 4 has the highest count among even magnitudes, so 4 is reported.
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 →