Most Words in One Sentence. Each nonempty sentence consists of lowercase words separated by exactly one space, without leading or trailing spaces. Return the largest word count among the given sentences.
### Problem
Each string in `sentences` is a nonempty sentence of lowercase English words separated by a single space, with no leading or trailing spaces. Return the greatest number of words in any one of the sentences.
```cpp
class Solution {
public:
int mostWordsFound(vector<string>& sentences);
};
```
### Examples
**Example 1:**
```text
sentences = ["small birds fly","rain falls"]
Output: 3
Explanation: The first sentence has three words and the second has two.
```
**Example 2:**
```text
sentences = ["hello","good day"]
Output: 2
Explanation: The second sentence has one separator and two words.
```
### Constraints
- `1 <= sentences.length <= 100`.
- Sentence lengths lie in `[1,100]` and use only lowercase letters and spaces.
- No leading, trailing or repeated separator spaces.
### Clarifying Questions
Words are nonempty and are separated by exactly one space. Empty sentences are outside the source domain.
```hint Inspect the structure
How many separators does a sentence with w words have?
```
### Reasoning checkpoints
- Count complete words according to the guaranteed sentence formatting.
- Return the largest count for one sentence rather than a total across sentences.
- Handle single-word sentences and several sentences tied for the largest count.
### Optional extensions
How would arbitrary repeated whitespace change the counting rule?
Overview: Most Words in One Sentence. Each nonempty sentence consists of lowercase words separated by exactly one space, without leading or trailing spaces. Return the largest word count among the given sentences.
Each string in sentences is a nonempty sentence of lowercase English words separated by a single space, with no leading or trailing spaces. Return the greatest number of words in any one of the sentences.
class Solution {
public:
int mostWordsFound(vector<string>& sentences);
};
Examples
Example 1:
sentences = ["small birds fly","rain falls"]
Output: 3
Explanation: The first sentence has three words and the second has two.
Example 2:
sentences = ["hello","good day"]
Output: 2
Explanation: The second sentence has one separator and two words.
Constraints
1 <= sentences.length <= 100
.
Sentence lengths lie in
[1,100]
and use only lowercase letters and spaces.
No leading, trailing or repeated separator spaces.
Clarifying Questions Guidance
Words are nonempty and are separated by exactly one space. Empty sentences are outside the source domain.
Reasoning checkpoints
Count complete words according to the guaranteed sentence formatting.
Return the largest count for one sentence rather than a total across sentences.
Handle single-word sentences and several sentences tied for the largest count.
Optional extensions
How would arbitrary repeated whitespace change the counting rule?