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.
- Swap three variables without using temporary variable
- How to swap two numbers without using a 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 words in a given string
- Reverse vowels in a given string
- Reverse a string in Java
- Reverse string in Python (5 different ways)
- Reverse alternate k characters in a string
- Reverse words in a given String in Java
- Reverse middle words of a string
- Reverse String according to the number of words
- Reverse words in a given String in Python
- Print reverse of a string using recursion
- Print reverse string after removing vowels