You are given a string s. A word is a run of characters that are not spaces. Words are separated by one or more spaces.
Return a string that has the words of s in reverse order, with exactly one space between two words.
s may have extra spaces at the start, at the end, or between words. The answer must not have any extra space.
Examples
Example 1:
Input: s = " chai and samosa "
Output: "samosa and chai"
Explanation: The space at the start and the space at the end are removed, and the words are in reverse order.
Example 2:
Input: s = "monsoon"
Output: "monsoon"
Explanation: There is only one word, so nothing changes.
Example 3:
Input: s = "learn code repeat"
Output: "repeat code learn"
Explanation: The three words come out in the opposite order.