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
< ? php function canBePicked ( $ digits , $ num ) { $ copyDigits = array ( ) ; for ( $ i = 0 ; $ i < sizeof ( $ digits ) ; $ i ++ ) $ copyDigits [ $ i ] = $ digits [ $ i ] ; while ( $ num > 0 ) { $ digit = $ num % 10 ; if ( $ copyDigits [ $ digit ] == 0 ) return false ; else $ copyDigits [ $ digit ] -- ; $ num = floor ( $ num / 10 ) ; } return true ; } function countAlphabets ( $ n ) { $ count = 0 ; $ digits = array_fill ( 0 , 10 , 0 ) ; while ( $ n > 0 ) { $ digit = $ n % 10 ; $ digits [ $ digit ] ++ ; $ n = floor ( $ n / 10 ) ; } for ( $ i = ord ( ' a ' ) ; $ i <= ord ( ' z ' ) ; $ i ++ ) if ( canBePicked ( $ digits , $ i ) ) $ count ++ ; for ( $ i = ord ( ' A ' ) ; $ i <= ord ( ' Z ' ) ; $ i ++ ) if ( canBePicked ( $ digits , $ i ) ) $ count ++ ; return $ count ; } $ n = 1623455078 ; echo countAlphabets ( $ n ) ; ? >