Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters. The words in s will be separated by at least one space. Return a string of the words in reverse order concatenated by a single space. Note that s may contain leading or trailing spaces or multiple spaces between two words. The returned string should only have a single space separating the words. Do not include any extra spaces.
Example 1
Input: s = the sky is blue
Output: blue is sky the
Explanation: The four words the, sky, is and blue are listed in reverse order, separated by single spaces.
Example 2
Input: s = hello world
Output: world hello
Explanation: The leading and trailing spaces are dropped, and the two words are reversed.
Example 3
Input: s = a good example
Output: example good a
Explanation: The multiple spaces between "good" and "example" collapse to one, and the words are reversed.
Splitting on whitespace naturally drops leading, trailing, and repeated spaces and yields the words as a list. Reverse that list and join it back with single spaces.
Run checks all cases above. Submit evaluates all test cases.