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:
- Lexicographically smaller string by swapping at most one character pair
- 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 if a string is made up of K alternating characters
- 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
- Count of lexicographically smaller characters on right
- Check if a string is substring of another
- Check if the given string is shuffled substring of another string
- 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
- Check if there exists a permutation of given string which doesn't contain any monotonous substring
- Lexicographically smallest and largest substring of size k
- Lexicographically smallest substring with maximum occurrences containing a's and b's only
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.