Generating distinct subsequences of a given string in lexicographic order | C # program to print all distinct subsequences of a string . ; 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
using System ; using System . Collections . Generic ; class GFG { static void generate ( HashSet < String > st , String s ) { if ( s . Length == 0 ) { return ; } if ( ! st . Contains ( s ) ) { st . Add ( s ) ; for ( int i = 0 ; i < s . Length ; i ++ ) { String t = s ; t = t . Substring ( 0 , i ) + t . Substring ( i + 1 ) ; generate ( st , t ) ; } } return ; } public static void Main ( String [ ] args ) { String s = " xyz " ; HashSet < String > st = new HashSet < String > ( ) ; generate ( st , s ) ; foreach ( String str in st ) { Console . WriteLine ( str ) ; } } }