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 readonly set of sequences ; Recursively call function ; Backtrack to its previous state ; Driver Code ; Function Call ; Print required sequences
var combination = " " ; var combinations = [ ] ; function printSequences ( combinations ) { for ( var s of combinations ) { document . write ( s + " " ) ; } } function generateCombinations ( s , n ) { for ( var i = 0 ; i < s . length ; i ++ ) { combination += s [ i ] ; var x = parseInt ( combination ) ; if ( x <= n ) { combinations . push ( combination ) ; generateCombinations ( s , n ) ; } combination = combination . substring ( 0 , combination . length - 1 ) ; } } var S = " " ; var N = 100 ; generateCombinations ( S , N ) ; printSequences ( combinations ) ;