Warm-ups · 18 of 24
Reverse the order of words
Return the words in reverse order, separated by single spaces, with no spaces at the start or end.
Examples
Input s = "the sky is blue"
Output "blue is sky the"
Input s = " hello world "
Output "world hello"
Extra spaces disappear.
📘 New to this? Building a new string or array as the answer explains the idea in a few minutes.
Solved it? The same idea on LeetCode: try it there ↗