Print all combinations generated by characters of a numeric string which does not exceed N | Store the current sequence of s ; Store the all the required sequences ; Function to print all sequences of S satisfying the required condition ; Print all strings in the set ; Function to generate all sequences of string S that are at most N ; Iterate over string s ; Push ith character to combination ; Convert the string to number ; Check if the condition is true ; Push the current string to the final set of sequences ; Recursively call function ; Backtrack to its previous state ; Driver Code ; Function Call ; Print required sequences
combination = " " ; NEW_LINE combinations = [ ] ; NEW_LINE def printSequences ( combinations ) : NEW_LINE INDENT for s in ( combinations ) : NEW_LINE INDENT print ( s , end = ' ▁ ' ) ; NEW_LINE DEDENT DEDENT def generateCombinations ( s , n ) : NEW_LINE INDENT global combination ; NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT combination += s [ i ] ; NEW_LINE x = int ( combination ) ; NEW_LINE if ( x <= n ) : NEW_LINE INDENT combinations . append ( combination ) ; NEW_LINE generateCombinations ( s , n ) ; NEW_LINE DEDENT combination = combination [ : - 1 ] ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT S = "124" ; NEW_LINE N = 100 ; NEW_LINE generateCombinations ( S , N ) ; NEW_LINE printSequences ( combinations ) ; NEW_LINE DEDENT