Generating distinct subsequences of a given string in lexicographic order | Finds and stores result in st for a given string s . ; If current string is not already present . ; Traverse current string , one by one remove every character and recur . ; Driver code
function generate ( st , s ) { if ( s . length == 0 ) return st ; if ( ! st . has ( s ) ) { st . add ( s ) ; for ( let i = 0 ; i < s . length ; i ++ ) { let t = s ; t = t . substr ( 0 , i ) + t . substr ( i + 1 ) ; st = generate ( st , t ) ; } } return st ; } let s = " " ; let st = new Set ( ) ; st = generate ( st , s ) ; let str = ' ' ; console . log ( st ) for ( item of st . values ( ) ) str += item + ' ' document . write ( str ) ;