The string s is a line of text made of words and spaces. A word is a run of characters with no space in it; words are kept apart by one or more spaces. Return the same words in reverse order, with exactly one space between neighbouring words.
s can be untidy: it may begin or end with spaces, and two words may have several spaces between them. Your answer must be tidy: no space at the start, none at the end, and never two in a row. Each word itself stays as it is, letter for letter.
Five words, read back from the last one to the first.
The three spaces in front, the two in the middle and the one at the end all disappear. Only the single space between the two words is left.
Digits and capital letters are word characters like any other, and the words keep their case.
Constraints
1 <= s.length <= 10⁴s is made of English letters (lowercase and uppercase), digits and spaces ' '.s holds at least one word.Get the words out first and ignore how many spaces sit between them. The answer is just those words, from the last one to the first, joined by single spaces.