Reverse the words
Mediumstringtwo pointers
Reverse the order of words in s. There may be extra spaces at the ends or between words; the result must have words separated by single spaces, with no leading or trailing spaces.
Example 1
Input: s = "the sky is blue" Output: "blue is sky the"
Example 2
Input: s = " hello world " Output: "world hello"
Constraints
- 1 ≤ s.length ≤ 10⁴
- s contains at least one word
Submit checks your solution against 8 tests, including hidden ones.
/**
* @param {string} s
* @return {string}
*/
function reverseWords(s) {
}