Reverse Each Word in a String
Basic String Manipulation DSA practice problem on Onlearn.
Difficulty: easy.
Topics: How can you reverse every word in a string?, Strings, String Manipulation, Loops, Two Pointers, in-place algorithms, iteration, string manipulation, String Splitting & Joining.
Problem: Reverse Words in a Sentence Given a string s representing a sentence, reverse each word in the sentence, while maintaining the original order of words and spaces. Input Specification The input will be a single line containing a string s. 1 <= len(s) <= 10^5 s consists of printable ASCII characters, including letters, digits, and spaces. Words are separated by one or more spaces. Leading or trailing spaces in the input should be preserved in the output. Output Specification Return the modified string where each word is reversed. Sample Test Cases Sample Input 1: Sample Output 1: Sample Input 2: Sample Output 2: