Find The Least Frequent Digit

Given an integer n, find the digit that occurs least frequently in its decimal representation. If multiple digits have the same frequency, choose the smallest digit.

Return the chosen digit as an integer.

The frequency of a digit x is the number of times it appears in the decimal representation of n.

Example 1
Inputn = 1553322
Output1
The least frequent digit in n is 1, which appears only once, while all other digits appear twice.
Example 2
Inputn = 723344511
Output2
The least frequent digits in n are 7, 2, and 5; each appears only once, so the smallest is 2.

Constraints

  • 1 <= n <= 2^31​​​​​​​ - 1

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate