Given a string, find concatenation of all substrings in lexicographic order.
Input : s = “abc”
Output : aababcbbcc
The substrings of s in lexicographic order are “a”, “b”, “c”, “ab”, “abc”, “bc”. Concatenation of substrings is “a”+”ab”+”abc”+”b”+”bc”+”c” = “aababcbbcc”.
Input : s = “cba”
Output : abbaccbcba
1. Find all the substrings of string and store it in a string array. The size of array would be n*(n+1)/2 where n is length of input string.
2. Sort the string array to make them all in lexicographical order.
3. Concatenate the strings of string array in another empty string.
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Longest palindromic string formed by concatenation of prefix and suffix of a string
- K-th lexicographical string of given length
- Lexicographical Maximum substring of string
- Print all the combinations of a string in lexicographical order
- Find the k-th string in lexicographical order consisting of n-2 X's and 2 Y's
- Largest lexicographical string with at most K consecutive elements
- Print Concatenation of Zig-Zag String in 'n' Rows
- Ropes Data Structure (Fast String Concatenation)
- Longest palindromic String formed using concatenation of given strings in any order
- Number of substrings of a string
- Replace two substrings (of a string) with each other
- Program to print all substrings of a given string
- Split the string into substrings using delimiter
- Count of substrings of a binary string containing K ones
- Sum of all substrings of a string representing a number | Set 1
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.