![]() |
VOOZH | about |
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].
Examples:
Input: str = "geeksforgeeks", L = 5, R = 7
Output: geeksrofgeeks
Reverse the characters in the range str[5...7] = "geeksforgeeks"
and the new string will be "geeksrofgeeks"Input: str = "ijklmn", L = 1, R = 2
Output: ikjlmn
Approach:
Below is the implementation of the above approach:
geeksrofgeeks
Time complexity: O(N), where N = (r - l)/2
Auxiliary space: O(1)