Easy · Strings

Reverse Words in a String

Given a string s of words separated by one or more spaces (possibly with leading or trailing spaces), return its words in reverse order joined by single spaces, with no spaces at either end.

Examples

Example 1

{
  "s": "the sky is blue"
}

Output: "blue is sky the"

Example 2

{
  "s": "  hello   world  "
}

Output: "world hello"

Rebuild it in the studio

Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.

More Strings problems