Count of alphabets whose ASCII values can be formed with the digits of N | C ++ implementation of the approach ; Function that returns true if num can be formed with the digits in digits [ ] array ; Copy of the digits array ; Get last digit ; If digit array doesn 't contain  current digit ; One occurrence is used ; Remove the last digit ; Function to return the count of required alphabets ; To store the occurrences of digits ( 0 - 9 ) ; Get last digit ; Update the occurrence of the digit ; Remove the last digit ; If any lowercase character can be picked from the current digits ; If any uppercase character can be picked from the current digits ; Return the required count of alphabets ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool canBePicked ( int digits [ ] , int num ) { int copyDigits [ 10 ] ; for ( int i = 0 ; i < 10 ; i ++ ) copyDigits [ i ] = digits [ i ] ; while ( num > 0 ) { int digit = num % 10 ; if ( copyDigits [ digit ] == 0 ) return false ; else copyDigits [ digit ] -= 1 ; num = floor ( num / 10 ) ; } return true ; } int countAlphabets ( long n ) { int count = 0 ; int digits [ 10 ] = { 0 } ; while ( n > 0 ) { int digit = n % 10 ; digits [ digit ] += 1 ; n = floor ( n / 10 ) ; } for ( int i = 97 ; i <= 122 ; i ++ ) if ( canBePicked ( digits , i ) ) count += 1 ; for ( int i = 65 ; i < 91 ; i ++ ) if ( canBePicked ( digits , i ) ) count += 1 ; return count ; } int main ( ) { long n = 1623455078 ; cout << ( countAlphabets ( n ) ) ; }