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 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; void FindSub ( set < string > & sub , set < char > & ch , string str , string res , int i ) { if ( i == str . length ( ) ) { sub . insert ( res ) ; return ; } if ( ! ch . count ( str [ i ] ) ) { ch . insert ( str [ i ] ) ; res . push_back ( str [ i ] ) ; FindSub ( sub , ch , str , res , i + 1 ) ; res . pop_back ( ) ; ch . erase ( str [ i ] ) ; } FindSub ( sub , ch , str , res , i + 1 ) ; } void printSubwithUniqueChar ( string str , int N ) { set < string > sub ; set < char > ch ; FindSub ( sub , ch , str , " " , 0 ) ; for ( auto subString : sub ) { cout << subString << " ▁ " ; } } int main ( ) { string str = " abac " ; int N = str . length ( ) ; printSubwithUniqueChar ( str , N ) ; return 0 ; }