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:
- Check whether two strings can be made equal by reversing substring of equal length from both strings
- Lexicographically smaller string by swapping at most one character pair
- Find if a given string can be represented from a substring by iterating the substring “n” times
- Lexicographically smallest and largest anagrams of a string containing another string as its substring
- 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
- Check if permutation of a given string can be made palindromic by removing at most K characters
- String obtained by reversing and complementing a Binary string K times
- Count of lexicographically smaller characters on right
- K-th lexicographically smallest unique substring of a given string
- Check if there exists a permutation of given string which doesn't contain any monotonous substring
- Check whether two strings can be made equal by increasing prefixes
- Check whether an array can be made strictly increasing by modifying atmost one element
- Queries to check whether all the elements can be made positive by flipping signs exactly K times
- Check if the rows of a binary matrix can be made unique by removing a single column
- Check whether two strings can be made equal by copying their characters with the adjacent ones
- Check if two strings can be made equal by swapping one character among each other
- Check if all bits can be made same by flipping two consecutive bits
- Check if all strings of an array can be made same by interchanging characters
- Find the longest string that can be made up of other strings from the array
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.