Given a string str, print reverse all words except the first and last words.
Input : Hi how are you geeks Output : Hi woh era uoy geeks Input : I am fine Output : I ma fine
- Print the first word.
- For remaining middle words, print reverse of every word after reaching end of it. This will print reverse of all words except the last word.
- Print last word.
Hi woh era uoy geeks
Time Complexity : O(n)
Auxiliary Space : O(L) where L is length of the longest word in the string.
- Reverse words in a given string
- Reverse String according to the number of words
- Reverse words in a given String in Python
- Reverse words in a given String in Java
- Print words of a string in reverse order
- Reverse Middle X Characters
- Sorting array with reverse around middle
- Check if the given string of words can be formed from words present in the dictionary
- Reverse individual words
- Reverse individual words with O(1) extra space
- Lexicographically middle string
- Create a new string by alternately combining the characters of two halves of the string in reverse
- Count words in a given string
- Shortest substring of a string containing all given words
- Minimum Distance Between Words of a String
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.