Reverse Words in a String III

Given a string s, reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.

Example 1
Inputs = "Let's take LeetCode contest"
Output"s'teL ekat edoCteeL tsetnoc"
Each word's characters are reversed, while the words remain in their original order separated by single spaces.
Example 2
Inputs = "Mr Ding"
Output"rM gniD"
Both words are individually reversed while preserving their order and the single space between them.

Constraints

  • 1 <= s.length <= 5 * 10^4
  • s contains printable ASCII characters.
  • s does not contain any leading or trailing spaces.
  • There is at least one word in s.
  • All the words in s are separated by a single space.

Asked at 6 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate