We are given a string. We are also given indexes of first and last characters in string. The task is to reverse the string without using any extra variable.
Input : str = "abc" Output : str = "cba" Input : str = "GeeksforGeeks" Output : str = "skeeGrofskeeG"
If we are allowed to library function, we can also use the idea discussed in quickly reverse a string in C++. We don’t even need indexes of first and last characters.
This article is contributed by Mr. Somesh Awasthi. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- How to swap two numbers without using a temporary variable?
- Swap three variables without using temporary variable
- Create a new string by alternately combining the characters of two halves of the string in reverse
- Reverse a string in Java
- Reverse the given string in the range [L, R]
- Reverse words in a given string
- Reverse vowels in a given string
- Different methods to reverse a string in C/C++
- Reverse words in a given String in Java
- Reverse alternate k characters in a string
- Print reverse of a string using recursion
- Reverse string in Python (5 different ways)
- Reverse String according to the number of words
- Reverse every word of the string except the first and the last character
- Reverse middle words of a string