Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Reverse Words in a String

Medium Strings

Given a string s, reverse the order of its words. Words are separated by one or more spaces. The output must contain the words separated by a single space with no leading or trailing spaces.

Constraints

1 <= len(s) <= 10^4 s has at least one word

Discussion

No discussions yet.

Rewards · v2.1

Join Shalyam Newsletter

Get exclusive insights with every issue: education, research and innovation news.

One email a week. Unsubscribe any time.