Dsa
Strings
Warm-up
Reverse Words
Given a sentence consisting of words separated by spaces, write a program that reverses the order of words. A word is defined as a maximal substring consisting of non-space characters. The input ends with a newline character.
Input Format:
A single line containing the sentence.
Output Format:
A single line with the words in reverse order, separated by a single space.
Example:
Input:
Hello World from OpenAI
Output:
OpenAI from World Hello
Key concepts
stringsmanipulation
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now