Maximum Number of Words in a Sentence
EasyArrayMath
Description
A sentence is a list of words separated by a single space. Given an array of sentences, return the maximum number of words that appear in a single sentence.
Examples
Input:
sentences = ["alice and bob love leetcode","i think so too","this is great thanks very much"]Output:
6Explanation:
Last sentence has 6 words.
Input:
sentences = ["hello world", "programming is fun and challenging", "code"]Output:
5Explanation:
The first sentence has 2 words, the second sentence has 5 words, and the third sentence has 1 word. The maximum is 5 words.
Input:
sentences = ["welcome to the coding interview", "good luck", "you can do it well today"]Output:
6Explanation:
The first sentence has 5 words, the second sentence has 2 words, and the third sentence has 6 words. The maximum is 6 words.
Constraints
- •
1 ≤ sentences.length ≤ 100
Ready to solve this problem?
Practice solo and sharpen your skills for technical interviews.