A regional warehouse stamps every incoming shipment with a numeric manifest code. An auditor wants to flag, for each manifest, the single digit (0 through 9) that shows up the least often within that code, since rare digits are used to spot-check for transcription errors. You are given one manifest code and must report its rarest digit.
Only digits that actually appear in the code are considered candidates (a digit that never appears is not a candidate). If two or more digits tie for the fewest occurrences, report the smallest of those tied digits.
A single line containing the manifest code as a string of decimal digits, with no sign and no leading zero unless the code is exactly the single digit 0.
Print a single character: the rarest digit in the code, as described above.
0123456789.0.Example 1
Input
1223334
Expected
1
Explanation
Digit counts are 1->1, 2->2, 3->3, 4->1. The smallest count is 1, shared by digits 1 and 4. Between those tied digits, the smaller one is 1, so the answer is 1.
Example 2
Input
77788899
Expected
9
Explanation
Digit counts are 7->3, 8->3, 9->2. The smallest count is 2, achieved only by digit 9, so the answer is 9.
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 →