An image-processing tool samples n pixel color codes (24-bit RGB integers, range 0 to 16777215) from an image. Find the color code that occurs the fewest times among the samples. If two or more codes tie for the fewest occurrences, output the largest such code.
Line 1: an integer n.
Line 2: n space-separated integers, each in [0, 16777215].
A single integer: the least-frequent color code, with ties broken by the largest code value.
Example 1
Input
6 10 10 20 30 30 30
Expected
20
Explanation
10 occurs twice, 30 occurs three times, and 20 occurs only once — the fewest. Since 20 is the only code with the minimum frequency, it is the answer.
Example 2
Input
5 1 2 3 4 1
Expected
4
Explanation
1 occurs twice; 2, 3, and 4 each occur once, tied for the fewest. The tie-break picks the largest of these, which is 4.
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 →