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.
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.
- 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 string whose hamming distance from given string is exactly K
- Lexicographically middle string
- Lexicographically n-th permutation of a string
- Lexicographically first palindromic string
- Lexicographically largest string possible in one swap
- Lexicographically largest sub-sequence of the given string
- Lexicographically smallest string after M operations
- Lexicographically smallest string of length N and sum K
- Lexicographically next greater string using same character set
- Lexicographically minimum string rotation | Set 1
- Find n-th lexicographically permutation of a string | Set 2
- K-th lexicographically smallest unique substring of a given string
- Lexicographically all Shortest Palindromic Substrings from a given string
- Replace every vowels with lexicographically next vowel in a String
- Lexicographically smallest permutation of a string with given subsequences
- Lexicographically first alternate vowel and consonant string
- Queries to answer the X-th smallest sub-string lexicographically
- Find lexicographically smallest string in at most one swaps