EditorialPut the first character of the sentence into the answer. Whenever a space is encountered, append the character immediately following it. Every character is inspected once, so the time complexity is O(∣S∣)O(|S|)O(∣S∣).