Given a string S, the task is to check if we can make the string lexicographically smaller by reversing any sub-string of the given string.
Input: S = “striver”
Reverse “rive” to get “stevirr” which is lexicographically smaller.
Input: S = “rxz”
Approach: Iterate in the string and check if for any index s[i] > s[i + 1]. If there exists at least one such index, then it is possible else not.
Below is the implementation of the above approach:
- K-th lexicographically smallest unique substring of a given string
- Check if a given string is made up of two alternating characters
- Check if a two character string can be made using given words
- Check whether the string S1 can be made equal to S2 with the given operation
- Queries to check if string B exists as substring in string A
- Check if a string is substring of another
- Python | Check if a Substring is Present in a Given String
- Check if string can be rearranged so that every Odd length Substring is Palindrome
- Lexicographically smallest substring with maximum occurrences containing a's and b's only
- Lexicographically smallest and largest substring of size k
- 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
- 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
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.