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
def nonLower ( s ) : NEW_LINE INDENT for i in range ( len ( s ) ) : NEW_LINE INDENT if not s [ i ] . islower ( ) : NEW_LINE INDENT return True NEW_LINE DEDENT DEDENT return False NEW_LINE DEDENT def printCodes ( output ) : NEW_LINE INDENT for i in range ( len ( output ) ) : NEW_LINE INDENT if ( nonLower ( output [ i ] ) ) : NEW_LINE INDENT continue NEW_LINE DEDENT print ( output [ i ] ) NEW_LINE DEDENT DEDENT def getChar ( n ) : NEW_LINE INDENT return chr ( n + 96 ) NEW_LINE DEDENT def getCode ( str ) : NEW_LINE INDENT if ( len ( str ) == 0 ) : NEW_LINE INDENT ans = [ " " ] NEW_LINE return ans NEW_LINE DEDENT output1 = getCode ( str [ 1 : ] ) NEW_LINE output2 = [ ] NEW_LINE firstDigit = ( ord ( str [ 0 ] ) - ord ( '0' ) ) NEW_LINE firstTwoDigit = 0 NEW_LINE if ( len ( str ) >= 2 ) : NEW_LINE firstTwoDigit = ( ( ord ( str [ 0 ] ) - ord ( '0' ) ) * 10 + ( ord ( str [ 1 ] ) - ord ( '0' ) ) ) NEW_LINE if ( firstTwoDigit >= 10 and firstTwoDigit <= 26 ) : NEW_LINE INDENT output2 = getCode ( str [ 2 : ] ) NEW_LINE DEDENT output = [ ' ' for i in range ( len ( output1 ) + len ( output2 ) ) ] NEW_LINE k = 0 NEW_LINE for i in range ( len ( output1 ) ) : NEW_LINE INDENT ch = getChar ( firstDigit ) NEW_LINE output [ i ] = ch + output1 [ i ] NEW_LINE k += 1 NEW_LINE DEDENT for i in range ( len ( output2 ) ) : NEW_LINE INDENT ch = getChar ( firstTwoDigit ) NEW_LINE output [ k ] = ch + output2 [ i ] NEW_LINE k += 1 NEW_LINE DEDENT return output NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT input = "101" NEW_LINE output = getCode ( input ) NEW_LINE printCodes ( output ) NEW_LINE DEDENT