Check if frequency of each digit is less than the digit | A C ++ program to validate a number ; Function to validate number ( Check iffrequency of a digit is less than thedigit itself or not ) ; If current digit of temp is same as i ; if frequency is greater than digit value , return false ; driver program
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool validate ( long long int n ) { for ( int i = 0 ; i < 10 ; i ++ ) { long long int temp = n ; int count = 0 ; while ( temp ) { if ( temp % 10 == i ) count ++ ; if ( count > i ) return false ; temp /= 10 ; } } return true ; } int main ( ) { long long int n = 1552793 ; if ( validate ( n ) ) cout << " True " ; else cout << " False " ; return 0 ; }