Given a string str, and two integers L and R, the task is to reverse the string in the range [L, R] i.e. str[L…R].
Input: str = “geeksforgeeks”, L = 5, R = 7
Reverse the characters in the range str[5…7] = “geeksforgeeks”
and the new string will be “geeksrofgeeks”
Input: str = “ijklmn”, L = 1, R = 2
- If the range is invalid i.e. either L < 0 or R ≥ len or L > R then print the original string.
- If the range is valid then keep swapping the characters str[L] and str[R] while L < R and update L = L + 1 and R = R – 1 after every swap operation. Print the updated string in the end.
Below is the implementation of the above approach:
- Create a new string by alternately combining the characters of two halves of the string in reverse
- String Range Queries to find the number of subsets equal to a given String
- PHP | Reverse a String
- Reverse vowels in a given string
- Reverse words in a given string
- Reverse a string in Java
- Different methods to reverse a string in C/C++
- Reverse String according to the number of words
- Reverse words in a given String in Java
- Reverse string in Python (5 different ways)
- Reverse middle words of a string
- Reverse every word of the string except the first and the last character
- Print reverse of a string using recursion
- Reverse alternate k characters in a string
- Reverse words in a given String in Python
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.