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

Open every published interview problem, solution, scene, and memory room free, with no account.

More Strings problems