Reverse Word Order
EasyStringSorting
Description
Given a string s of words separated by single spaces, return a string with the words in reverse order.
Examples
Input:
s = "the quick brown fox"Output:
"fox brown quick the"Explanation:
Listing the words in reverse order produces "fox brown quick the".
Input:
s = "hello world"Output:
"world hello"Explanation:
Listing the words in reverse order produces "world hello".
Input:
s = "unit tests pass"Output:
"pass tests unit"Explanation:
Listing the words in reverse order produces "pass tests unit".
Constraints
- •
1 ≤ s.length ≤ 10⁴ - •
Words are separated by single spaces.
Ready to solve this problem?
Practice solo and sharpen your skills for technical interviews.