Given a string s, reverse the order of its words. A word is a maximal sequence of non-space characters. When you build the answer, remove any leading or trailing spaces and collapse every run of multiple spaces between words into a single space in the returned string. See the examples and constraints below, then consider the follow-up about solving it in-place.
Input / output
s: stringstring1 <= s.length <= 10^4s contains English letters, digits, punctuation, and spaces.Could you solve it in-place with O(1) extra space in a language that supports mutable fixed-size character arrays?