Reverse Words
Updated Jan 31, 2026
Problem
Given a sentence (a string of words separated by single spaces), reverse the order of the words.
Input: A single line containing a sentence.
Output: The sentence with words in reverse order.
Constraints
1 <= number of words <= 100
1 <= length of each word <= 100
Words are separated by single spaces.
Examples
Example 1
Input:
s = "hello world"
Output:
"world hello"
Example 2
Input:
s = "the sky is blue"
Output:
"blue is sky the"
Function Signature
def reverseWords(self, s: str) -> str
How to Submit
Implement a Solution class with a reverseWords method.
Your method will be called with the input parameters and should return the answer.