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 words in a given String in Java
- Reverse words in a given String in Python
- Reverse String according to the number of words
- 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
- 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
- Program to extract words from a given String
- Shortest substring of a string containing all given words
- Count words present in 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.