Maximum Number of Words Found in Sentences

A sentence is a list of words separated by single spaces, with no leading or trailing spaces. Given an array of strings sentences, return the largest number of words found in any single sentence.

30:00

Maximum Number of Words Found in Sentences
easy
Free written solution
Topics
Companies

A sentence is a list of words separated by single spaces, with no leading or trailing spaces. Given an array of strings sentences, return the largest number of words found in any single sentence.

Example 1:
Input: {"sentences":["alice and bob love leetcode","i think so too","this is great thanks very much"]}
Output: 6
Constraints:
  • 1≤sentences.length≤1001 \leq \text{sentences.length} \leq 100

  • 1≤sentences[i].length≤1001 \leq \text{sentences}[i].\text{length} \leq 100

  • sentences[i] consists only of lowercase English letters and spaces.

  • sentences[i] has no leading or trailing spaces, and words are separated by a single space.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"sentences":["alice and bob love leetcode","i think so too","this is great thanks very much"]}

Words are separated by exactly one space, so a sentence with k spaces has k + 1 words. Count each sentence and keep the largest.

sentences split into words

0

aliceandbobloveleetcode
?

1

ithinksotoo
?

2

thisisgreatthanksverymuch
?

word counts so far

best = 0
Variables
VariableValue
best0
DepthFunction Call
Stack empty
0/8