Warm-ups · 22 of 24
Count the words in a sentence
Return how many words the string has. Words are separated by one or more spaces, and there may be spaces at either end.
Examples
Input s = "hello world"
Output 2
Input s = " many spaces here "
Output 3
📘 New to this? Indexing and walking through an array explains the idea in a few minutes.