LeetCode solutions

3994. Find The Least Frequent Digit

My accepted Python solution to LeetCode problem 3994, Find The Least Frequent Digit, running in 0ms.

  • Difficulty: Easy
  • Python
  • Runtime 0ms
  • Memory 17.2MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.2MB, accepted 2025-12-30.

python
class Solution:
    def getLeastFrequentDigit(self, n: int) -> int:
        s = str(n)
        count = {}
        for c in s:
            count[c] = count.get(c, 0) + 1
        
        min_freq = min(count.values())
        for d in '0123456789':
            if d in count and count[d] == min_freq:
                return int(d)
        return -1

Source