182. Maximum Number of Words in Sentences

EasyStringString

You are given a list of sentences (each a string of words separated by single spaces, no leading/trailing spaces).

Return the maximum number of words that appear in a single sentence.

Input sentences are separated by '|' in the input string.

Input: A string of sentences separated by '|'. Each sentence has words separated by single spaces.

Output: An integer — the maximum word count across all sentences.

Examples

Example 1
Input: alice and bob love leetcode|i think so too|this is great thanks very much
Output: 6
Explanation: The third sentence has 6 words — the most.
Example 2
Input: please wait|continue to fight|continue to win
Output: 3
Explanation: All sentences have 3 words.
Example 3
Input: a|a b|a b c
Output: 3
Explanation: Last sentence has 3 words.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →