Count of alphabets whose ASCII values can be formed with the digits of N | 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
function canBePicked ( digits , num ) { var copyDigits = new Array ( 10 ) ; ; for ( var i = 0 ; i < 10 ; i ++ ) copyDigits [ i ] = digits [ i ] ; while ( num > 0 ) { var digit = num % 10 ; if ( copyDigits [ digit ] == 0 ) return false ; else copyDigits [ digit ] -= 1 ; num = Math . floor ( num / 10 ) ; } return true ; } function countAlphabets ( n ) { var count = 0 ; var digits = new Array ( 10 ) ; digits . fill ( 0 ) ; while ( n > 0 ) { var digit = n % 10 ; digits [ digit ] += 1 ; n = Math . floor ( n / 10 ) ; } for ( var i = 97 ; i <= 122 ; i ++ ) if ( canBePicked ( digits , i ) ) count += 1 ; for ( var i = 65 ; i < 91 ; i ++ ) if ( canBePicked ( digits , i ) ) count += 1 ; return count ; } var n = 1623455078 ; document . write ( countAlphabets ( n ) ) ;