Suppose we have a number n, we have to check whether the occurrence of each digit of n is less than or equal to digit itself.
So, if the input is like n = 5162569, then the output will be True as the digits and frequencies are (5, 2), (1, 1), (6, 2) and (9, 1), for all the frequency is either small or equal to the digit value.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def solve(n): for i in range(10): temp = n cnt = 0 while temp: if temp % 10 == i: cnt += 1 if cnt > i: return False temp //= 10 return True s = 5162569 print(solve(s))