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
- Different methods to reverse a string in C/C++
- Reverse vowels in a given string
- Reverse a string in Java
- Reverse words in a given string
- Reverse string in Python (5 different ways)
- Reverse String according to the number of words
- Reverse middle words of a string
- Reverse alternate k characters in a string
- Reverse words in a given String in Java
- Print reverse of a string using recursion
- Reverse words in a given String in Python
- Print reverse string after removing vowels