Given a string str, print of all the combinations of a string in lexicographical order.
Input: str = "ABC" Output: A AB ABC AC ACB B BA BAC BC BCA C CA CAB CB CBA Input: ED Output: D DE E ED
Approach: Count the occurrences of all the characters in the string using a map, then using recursion all the possible combinations can be printed. Store the elements and their counts in two different arrays. Three arrays are used, input array which has the characters, count array has the count of characters and result is a temporary array which is used in recursion to generate all the combinations. Using recursion and backtracking all the combinations can be printed.
Below is the implementation of the above approach.
A AB ABC AC ACB B BA BAC BC BCA C CA CAB CB CBA
- Print all longest common sub-sequences in lexicographical order
- Print all distinct circular strings of length M in lexicographical order
- Sort the words in lexicographical order in Python
- Print a number as string of 'A' and 'B' in lexicographic order
- Lexicographical concatenation of all substrings of a string
- Lexicographical Maximum substring of string
- Print all combinations of factors (Ways to factorize)
- Print all possible combinations of words from Dictionary using Trie
- Print all possible combinations of r elements in a given array of size n
- Combinations in a String of Digits
- Print all permutations in sorted (lexicographic) order
- Print array elements in alternatively increasing and decreasing order
- Print the last k nodes of the linked list in reverse order | Recursive approach
- Print all possible ways to convert one string into another string | Edit-Distance
- Find a string in lexicographic order which is in between given two strings
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.