Problem Submissions Solution

Reverse Words In A String

Difficulty: Easy

Acceptance: %

Points: 20.00

Given a string s, reverse the order of the words in the string while keeping the individual words unchanged. Words are separated by spaces.

Note: The output string should have words separated by a single space, with no extra spaces at the beginning or end.

Topics

Companies

Articles

Examples:

Expected Time Complexity: O(n)

Expected Space Complexity: O(n)

Constraints:
  • 1 <= s.size() <= 10^6
  • String s contains only lowercase English alphabets and spaces.
Companies:
Amazon Microsoft Adobe Goldman Sachs Cisco + 1 more
Topics:
String
Locked Content
Access Restricted: Please Login to access the code editor and test cases.