- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Check if frequency of each digit is less than the digit in Python

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 −

- for i in range 0 to 9, do
- temp := n, cnt := 0
- while temp is non-zero, do
- if temp mod 10 is same as i, then
- cnt := cnt + 1

- if cnt > i, then
- return False

- temp := quotient of (temp / 10)

- if temp mod 10 is same as i, then

- return True

## Example

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))

## Input

5162569

## Output

True

- Related Questions & Answers
- Largest number less than N with digit sum greater than the digit sum of N in C++
- C program to find frequency of each digit in a string
- Python – Average of digit greater than K
- Is the digit divisible by the previous digit of the number in JavaScript
- Check if all sub-numbers have distinct Digit product in Python
- Check if the frequency of any character is more than half the length of the string in Python
- Check if the first and last digit of the smallest number forms a prime in Python
- Find the frequency of a digit in a number using C++.
- Check whether sum of digit of a number is Palindrome - JavaScript
- Count of Binary Digit numbers smaller than N in C++
- Python - Check if all the values in a list are less than a given value
- Program to check we can get a digit pair and any number of digit triplets or not in Python
- Check if any value in an R vector is greater than or less than a certain value.
- Count of Numbers in Range where first digit is equal to last digit of the number in C++
- Find frequency of each element in a limited range array in less than O(n) time in C++

Advertisements