Medium · Strings
Reverse words
Given a string s of words separated by spaces, return s with its words in reverse order and its leading and trailing spaces removed; each gap between two words keeps its width ("a good day" → "day good a").
Examples
Example 1
{
"s": "the sky is"
}Output: "is sky the"
Example 2
{
"s": " hi bob "
}Output: "bob hi"
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.