Subsequences of given string consisting of non | C # program to implement the above approach ; Function to find all the subsequences of the string with non - repeating characters ; Base case ; Insert current subsequence ; If str [ i ] is not present in the current subsequence ; Insert str [ i ] into the set ; Insert str [ i ] into the current subsequence ; Remove str [ i ] from the set ; Not including str [ i ] from the current subsequence ; Utility function to print all subsequences of string with non - repeating characters ; Stores all possible subsequences with non - repeating characters ; Stores subsequence with non - repeating characters ; Traverse all possible subsequences containing non - repeating characters ; Print subsequence ; Driver Code
using System ; using System . Collections . Generic ; public class GFG { public static void FindSub ( HashSet < String > sub , HashSet < char > ch , String str , String res , int i ) { if ( i == str . Length ) { sub . Add ( res ) ; return ; } if ( ! ch . Contains ( str [ i ] ) ) { ch . Add ( str [ i ] ) ; FindSub ( sub , ch , str , res + str [ i ] , i + 1 ) ; ch . Remove ( str [ i ] ) ; } FindSub ( sub , ch , str , res , i + 1 ) ; } public static void printSubwithUniqueChar ( String str , int N ) { HashSet < String > sub = new HashSet < String > ( ) ; HashSet < char > ch = new HashSet < char > ( ) ; FindSub ( sub , ch , str , " " , 0 ) ; foreach ( String subString in sub ) { Console . Write ( subString + " ▁ " ) ; } } public static void Main ( String [ ] args ) { String str = " abac " ; int N = str . Length ; printSubwithUniqueChar ( str , N ) ; } }