Given a string, find lexicographically next string.
Input : geeks Output : geekt The last character 's' is changed to 't'. Input : raavz Output : raawz Since we can't increase last character, we increment previous character. Input : zzz Output : zzza
If string is empty, we return ‘a’. If string contains all characters as ‘z’, we append ‘a’ at the end. Otherwise we find first character from end which is not z and increment it.
This article is contributed by Pawan Asipu. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
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 a string such that every character is lexicographically greater than its immediate next character
- Lexicographically next greater string using same character set
- Replace every vowels with lexicographically next vowel in a String
- Lexicographically next permutation in C++
- Lexicographically smallest string whose hamming distance from given string is exactly K
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- Lexicographically smallest and largest anagrams of a string containing another string as its substring
- Lexicographically smallest permutation of a string that contains all substrings of another string
- Lexicographically first palindromic string
- Lexicographically minimum string rotation | Set 1
- Lexicographically n-th permutation of a string
- Find n-th lexicographically permutation of a string | Set 2
- Lexicographically first alternate vowel and consonant string
- K-th lexicographically smallest unique substring of a given string
- Lexicographically smallest string obtained after concatenating array
- Lexicographically middle string
- Lexicographically smallest permutation of a string with given subsequences
- Lexicographically largest string formed from the characters in range L and R
- Lexicographically smallest string formed by removing at most one character