151. Reverse Words in a String
Practice Reverse Words in a String for free on NudgeCode: Medium, Two Pointers pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
A word is a maximal run of non-space characters in s. Return a string with the words of s in reverse order, joined by exactly one space.
s may start or end with spaces and may have several spaces between two words; none of those extra spaces should appear in the answer. The letters inside each word keep their order.
Example
s = "the sky is blue" -> "blue is sky the"
s = " hello world " -> "world hello"
s = "a good example" -> "example good a"
Constraints
- 1 <= s.length <= 10^4
scontains English letters (upper and lower case), digits and spaces' 'scontains at least one word