[Leet Code] Maximum Number of Words Found in Sentences

Input: sentences = ["alice and bob love leetcode", "i think so too", "this is great thanks very much"]
Output: 6
Explanation:
- The first sentence, "alice and bob love leetcode", has 5 words in total.
- The second sentence, "i think so too", has 4 words in total.
- The third sentence, "this is great thanks very much", has 6 words in total.
Thus, the maximum number of words in a single sentence comes from the third sentence, which has 6 words.
Input: sentences = ["please wait", "continue to fight", "continue to win"]
Output: 3
Explanation: It is possible that multiple sentences contain the same number of words.
In this example, the second and third sentences (underlined) have the same number of words.
func mostWordsFound(sentences []string) int {
max := 0
for word := range sentences{
if len(strings.Split(sentences[word], " ")) > max{
max = len(strings.Split(sentences[word], " "))
}
}

return max

}

--

--

--

Learning, and posting my findings!

Love podcasts or audiobooks? Learn on the go with our new app.

Liquidifty v0.7 — External collections, 721 support, open stats

SOLID Design Principles & Their Relevance

DevOps explained — Venture Capital perspective

Knowledge Sharing — Agile, Software Environment

[Leet Code] Maximum Depth Of Binary Tree

Raise the bar on - Network Performance

Post First Project Thoughts

Mac Os X Server Delete Software Updates

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Matthew Boyd

Matthew Boyd

Learning, and posting my findings!

More from Medium

Leetcode 8. String to Integer (atoi)

LeetCode 83- Remove Duplicates from Sorted List

MCLT — More Code Less Talk

The pandemic of Data Structures and Algorithms Courses

What is a Stack?