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

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.