#2114
Easy Algorithms Maximum number of words found in sentences
Array String
86.7% acceptance
Feb 25, 2026
1894
65
A sentence is a list of words that are separated by a single space with no leading or trailing spaces.
You are given an array of strings sentences, where each sentences[i] represents a single sentence.
Return the maximum number of words that appear in a single sentence.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn most_words_found(sentences: Vec<String>) -> i32 {
sentences
.iter()
.map(|s| s.split_whitespace().count() as i32)
.max()
.unwrap_or(0)
}
}