150. Reverse Words in a String II
MediumTwo Pointers
Given a character sequence `s` (words separated by single spaces, with no leading or trailing spaces), reverse the **order of the words**. The classic form of this problem asks you to do it **in place** with O(1) extra space using the character array itself. Return the resulting string with the word order reversed. For example, given `"the sky is blue"`, return `"blue is sky the"`.
Examples
Input: the sky is blue
Output: blue is sky the
Explanation: Word order reversed; letters within each word stay intact.
Constraints
- 1 <= s.length <= 10^5
- s contains printable ASCII characters.
- s does not contain any leading or trailing spaces.
- There is at least one word in s.
- All the words in s are separated by a single space.
Loading...
Run checks all cases above. Submit evaluates all test cases.