Subsequences of given string consisting of non | Function to find all the subsequences of the str1ing with non - repeating ch1aracters ; Base case ; Insert current subsequence ; If str1 [ i ] is not present in the current subsequence ; Insert str1 [ i ] into the set ; Insert str1 [ i ] into the current subsequence ; Remove str1 [ i ] from current subsequence ; Remove str1 [ i ] from the set ; Not including str1 [ i ] from the current subsequence ; Utility function to print all subsequences of str1ing with non - repeating ch1aracters ; Stores all possible subsequences with non - repeating ch1aracters ; Stores subsequence with non - repeating ch1aracters ; Traverse all possible subsequences containing non - repeating ch1aracters ; Print subsequence ; Driver Code
def FindSub ( sub , ch1 , str1 , res , i ) : NEW_LINE INDENT if ( i == len ( str1 ) ) : NEW_LINE INDENT sub . add ( res ) NEW_LINE return NEW_LINE DEDENT if ( str1 [ i ] not in ch1 ) : NEW_LINE INDENT ch1 . add ( str1 [ i ] ) NEW_LINE FindSub ( sub , ch1 , str1 , res + str1 [ i ] , i + 1 ) NEW_LINE res += str1 [ i ] NEW_LINE res = res [ 0 : len ( res ) - 1 ] NEW_LINE ch1 . remove ( str1 [ i ] ) NEW_LINE DEDENT FindSub ( sub , ch1 , str1 , res , i + 1 ) NEW_LINE DEDENT def printSubwithUniquech1ar ( str1 , N ) : NEW_LINE INDENT sub = set ( ) NEW_LINE ch1 = set ( ) NEW_LINE FindSub ( sub , ch1 , str1 , " " , 0 ) NEW_LINE temp = [ ] NEW_LINE for substr1ing in sub : NEW_LINE temp . append ( substr1ing ) NEW_LINE temp . sort ( reverse = False ) NEW_LINE for x in temp : NEW_LINE print ( x , end = " ▁ " ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT str2 = " abac " NEW_LINE N = len ( str2 ) NEW_LINE printSubwithUniquech1ar ( str2 , N ) NEW_LINE DEDENT