A choir director records the pitch code produced by every singer during a warm-up drill as a list of integers, one per singer. A pitch is called a solo if exactly one singer produced that exact pitch code during the drill; a pitch sung by two or more singers is not a solo. Among all solo pitches, report the value of the highest one. If every pitch code in the drill was produced by two or more singers, so that no solo pitch exists, report -1 instead.
Line 1: an integer n, the number of singers.
Line 2: n space-separated integers, the pitch code sung by each singer, in the order they sang.
A single integer: the highest solo pitch code, or -1 if none exists.
Example 1
Input
9 5 7 3 9 4 9 8 3 1
Expected
8
Explanation
Counting occurrences: 5,7,4,8,1 each appear once while 9 and 3 each appear twice. Among the solo pitches {5,7,4,8,1} the highest is 8.
Example 2
Input
4 9 9 8 8
Expected
-1
Explanation
Both 9 and 8 appear twice, so there is no pitch sung by exactly one singer, and the answer is -1.
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 →