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 email@example.com. 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.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- 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 using STL
- Lexicographic rank of a string
- Lexicographic rank of a string with duplicate characters
- Find the N-th lexicographic permutation of string using Factoradic method
- Find distinct characters in distinct substrings of a string
- Count subsequences in first string which are anagrams of the second string
- Print all distinct circular strings of length M in lexicographical order
- Count of 'GFG' Subsequences in the given string
- Print all subsequences of a string
- Number of subsequences as "ab" in a string repeated K times
- Number of subsequences in a given binary string divisible by 2
- Lexicographically smallest permutation of a string with given subsequences
- Print all subsequences of a string | Iterative Method
- Print all Subsequences of String which Start with Vowel and End with Consonant.