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 the current result and update the result if needed.
Below is the implementation:
We find the 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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Find if a given string can be represented from a substring by iterating the substring “n” times
- Partition given string in such manner that i'th substring is sum of (i-1)'th and (i-2)'th substring
- K-th lexicographical string of given length
- 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
- Print all lexicographical greater permutations of a given string
- Largest lexicographical string with at most K consecutive elements
- Lexicographical concatenation of all substrings of a string
- Length of the largest substring which have character with frequency greater than or equal to half of the substring
- Minimum length of substring whose rotation generates a palindromic substring
- Print all longest common sub-sequences in lexicographical order
- Sort the words in lexicographical order in Python
- Find the lexicographical next balanced bracket sequence
- Print all distinct circular strings of length M in lexicographical order
- Lexicographical smallest alternate Array
- Lexicographical ordering using Heap Sort
- Lexicographical smallest number after at most K consecutive swaps
- Generate all numbers up to N in Lexicographical Order
- Print all numbers up to N in words in lexicographical order
- Maximum splits in binary string such that each substring is divisible by given odd number
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.