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.
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≤100
1≤sentences[i].length≤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.