Reverse Each Word in a Sentence

Problem Given a sentence or paragraph, reverse the characters of each word in place while keeping the order of the words unchanged.

Input / Output

  • Input: string s containing words separated by spaces.
  • Output: a string in which every word's characters are reversed but the word sequence is preserved.

Constraints

  • 1 <= |s| <= 10^5.
  • Input may contain multiple consecutive spaces; clarify whether the original spacing must be preserved exactly or normalised.
  • Clarify punctuation handling: is "don't" one word reversed wholesale to "t'nod", or should punctuation stay anchored?

Example

  • "Hello World" -> "olleH dlroW".
  • Tricky case: "a bc" (two spaces) -> "a cb" when spacing is preserved — a naive split-and-join with single spaces would silently collapse it.
asked …
LeaderboardSalaryAccount