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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.2MB, accepted 2025-12-30.
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