2. Reverse the Words
easystring
Given a sentence s, return the words in reverse order joined by single spaces.
s may contain leading, trailing or repeated spaces, and none of them should appear in the output.
Example 1
Inputs = "the sky is blue"
Output"blue is sky the"
Example 2
Inputs = " hello world "
Output"world hello"
Example 3
Inputs = "a good example"
Output"example good a"
Constraints
- 1 ≤ s.length ≤ 10⁴
- s contains letters, digits and spaces
- at least one word