Android & iPhone apps are coming soon. Log in for a plan and reminders made for you →

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 ↗

Your code · Python

Stuck?