Given a string s we have to find the lexicographical maximum substring of a string
Input : s = "ababaa" Output : babaa Explanation : "babaa" is the maximum lexicographic susbtring formed from this string Input : s = "asdfaa" Output : sdfaa
The idea is simple, we traverse through all substrings. For every substring, we compare it with current result and update result if needed.
Below is the implementation:
We find largest character and all its indexes. Now we simply traverse through all instances of the largest character to find lexicographically maximum substring.
Here we follow the above approach.
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.
- Maximum length substring with highest frequency in a string
- Maximum splits in binary string such that each substring is divisible by given odd number
- Maximum number of set bits count in a K-size substring of a Binary String
- K-th lexicographical string of given length
- Find if a given string can be represented from a substring by iterating the substring “n” times
- Lexicographical concatenation of all substrings of a string
- Largest lexicographical string with at most K consecutive elements
- Print all lexicographical greater permutations of a given string
- Find the k-th string in lexicographical order consisting of n-2 X's and 2 Y's
- Print all the combinations of a string in lexicographical order
- Partition given string in such manner that i'th substring is sum of (i-1)'th and (i-2)'th substring
- Find length of longest subsequence of one string which is substring of another string
- Queries to check if string B exists as substring in string A
- Minimum changes required to make first string substring of second string
- Check if the given string is shuffled substring of another string
- Find the Substring with maximum product
- Maximum length substring having all same characters after k changes
- Lexicographically smallest substring with maximum occurrences containing a's and b's only
- Check if a string is substring of another
- Frequency of a substring in a string
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.