Loading...
Loading...
Kabir and his friends play a secret-message game on their class WhatsApp group. To hide a message, they write every word backwards but keep the words in the same order. So meet at office becomes teem ta eciffo.
Given a message, print its hidden form.
Example 1
Input
meet at office
Output
teem ta eciffo
Each word is reversed on its own. The order meet, at, office stays the same.
Example 2
Input
Java
Output
avaJ
One word: the whole line is reversed.
Try the problem first. Open one hint at a time.
A stack gives back its items in the reverse order of putting them in.
Push the letters of the current word one by one.
When you reach a space, pop every letter into the answer, then add the space.
The last word has no space after it, so empty the stack once more after the loop.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor