Given a string s, make a list of all possible combinations of letters of a given string S. If there are two strings with the same set of characters, print the lexicographically smallest arrangement of the two strings
For string abc, the list in lexicographic order subsequences are, a ab abc ac b bc c
Input : s = "ab" Output : a ab b Input : xyzx Output : x xx xy xyx xyz xyzx xz xzx y yx yz yzx z zx
The idea is to use a set (which is implemented using self balancing BST) to store subsequences so that duplicates can be tested.
To generate all subsequences, we one by one remove every character and recur for remaining string.
x xy xyz xz y yz z
This article is contributed by SANDEEP GAUR MNNIT. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Find a string in lexicographic order which is in between given two strings
- Print a number as string of 'A' and 'B' in lexicographic order
- Print all distinct characters of a string in order (3 Methods)
- Power Set in Lexicographic order
- Print all permutations in sorted (lexicographic) order
- Count Distinct Subsequences
- Lexicographic rank of a string
- Lexicographic rank of a string using STL
- Lexicographic rank of a string with duplicate characters
- Find distinct characters in distinct substrings of a string
- Count subsequences in first string which are anagrams of the second string
- Count of 'GFG' Subsequences in the given string
- Print all subsequences of a string
- Print all distinct circular strings of length M in lexicographical order
- Number of subsequences as "ab" in a string repeated K times