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.
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.
- Count pair of strings whose concatenation of substrings form a palindrome
- 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
- Find the k-th string in lexicographical order consisting of n-2 X's and 2 Y's
- Print all lexicographical greater permutations of a given string
- Print all the combinations of a string in lexicographical order
- Largest lexicographical string with at most K consecutive elements
- Print Concatenation of Zig-Zag String in 'n' Rows
- Ropes Data Structure (Fast String Concatenation)
- Generate a string whose all K-size substrings can be concatenated to form the given string
- 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
- Number of even substrings in a string of digits
- Sum of all substrings of a string representing a number | Set 1
- Different substrings in a string that start and end with given strings
- Count of substrings of a binary string containing K ones
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.