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 two character string can be made using given words
- Check if a given string is made up of two alternating characters
- 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
- Lexicographically smallest and largest substring of size k
- Lexicographically smallest substring with maximum occurrences containing a's and b's only
- 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 whose hamming distance from given string is exactly K
- Lexicographically next string
- Find length of longest subsequence of one string which is substring of another string
- Check whether two strings can be made equal by increasing prefixes
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.