Print all Possible Decodings of a given Digit Sequence | Function to check if all the characters are lowercase or not ; Traverse the string ; If any character is not found to be in lowerCase ; Function to print the decodings ; If all characters are not in lowercase ; Function to return the character corresponding to given integer ; Function to return the decodings ; Base case ; Recursive call ; Stores the characters of two digit numbers ; Extract first digit and first two digits ; Check if it lies in the range of alphabets ; Next recursive call ; Combine both the output in a single readonly output array ; Index of readonly output array ; Store the elements of output1 in readonly output array ; Store the elements of output2 in readonly output array ; Result the result ; Driver Code ; Function call ; Print function call
function nonLower ( s ) { for ( let i = 0 ; i < s . length ; i ++ ) { if ( ! ( s [ i ] . charCodeAt ( ) >= 97 && s [ i ] . charCodeAt ( ) <= 122 ) ) { return true ; } } return false ; } function printCodes ( output ) { for ( let i = 0 ; i < output . length ; i ++ ) { if ( nonLower ( output [ i ] ) ) continue ; document . write ( output [ i ] + " " ) ; } } function getChar ( n ) { return String . fromCharCode ( n + 96 ) ; } function getCode ( str ) { if ( str . length == 0 ) { let ans = [ " " ] ; return ans ; } let output1 = getCode ( str . substring ( 1 ) ) ; let output2 = new Array ( 0 ) ; let firstDigit = ( str [ 0 ] - ' ' ) ; let firstTwoDigit = 0 ; if ( str . length >= 2 ) { firstTwoDigit = ( str [ 0 ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ) * 10 + ( str [ 1 ] . charCodeAt ( ) - ' ' . charCodeAt ( ) ) ; if ( firstTwoDigit >= 10 && firstTwoDigit <= 26 ) { output2 = getCode ( str . substring ( 2 ) ) ; } } let output = new Array ( output1 . length + output2 . length ) ; let k = 0 ; for ( let i = 0 ; i < output1 . length ; i ++ ) { let ch = getChar ( firstDigit ) ; output [ i ] = ch + output1 [ i ] ; k ++ ; } for ( let i = 0 ; i < output2 . length ; i ++ ) { let ch = getChar ( firstTwoDigit ) ; output [ k ] = ch + output2 [ i ] ; k ++ ; } return output ; } let input = " " ; let output = getCode ( input ) ; printCodes ( output ) ;