Reverse Words in a Sentence
Explore how to reverse the order of words in a sentence without changing the order of letters within each word. This lesson teaches an in-place method that involves reversing the entire string and then each individual word, achieving linear time and constant space complexity.
We'll cover the following...
We'll cover the following...
Statement
Given a sentence (an array of characters), reverse the order of its words without affecting the order of letters within a given word. All operations must be done in place.
Example
The “Hello World” string should be reversed as “World Hello”.
Here’s another example of reversing words in a sentence:
Sample input
"Hello world."
Expected output
"world. Hello"
Note: The ...