FastPrepMaximum Word Count in a Sentence
Problems/Maximum Word Count in a Sentence

Maximum Word Count in a Sentence

LSEG logoLSEG● EasyFULLTIMEOA

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported maximum-word-count task and sentence delimiters match at about 90%. Alphabet, spacing, empty-input behavior and length bounds are exercise conventions.

Split text into sentences at each period ., question mark ? or exclamation mark !. The text after the last delimiter is also a sentence.

A word is a nonempty run of English letters. One or more spaces separate words within a sentence. Empty sentences have zero words.

Return the largest word count among the sentences, or 0 when there are no words.

Function

maximumSentenceWords(text: String) → int

Examples

Example 1

text = "One two!Three four five?Six."return = 3

The nonempty sentence word counts are 2, 3 and 1; the maximum is 3.

Example 2

text = "  A   b c  "return = 3

Repeated and surrounding spaces do not create empty words. The only sentence has three words.

Example 3

text = "...?!"return = 0

Every sentence is empty, so no words are counted.

Constraints

  • 0 <= text.length <= 100000.
  • text contains only English letters, ordinary spaces, periods, question marks and exclamation marks.

More LSEG Online Assessment questions

  • Count Times Using at Most Two DigitsOA · Seen Jul 2025
  • Maximum Sum of Exactly Three Non-Adjacent ElementsOA · Seen Jul 2025
  • Minimum Digit Swaps for the Smallest DifferenceOA · Seen Jul 2025
  • Smallest String After at Most One DeletionOA · Seen Jul 2025
  • Delete One Digit 5 to Maximize the NumberOA · Seen Feb 2025
  • Three-Part Partition with Minimum Largest RangeOA · Seen Feb 2025
  • Transform a String with at Most One OperationOA · Seen Feb 2025
  • Price Equity Options and ForwardsOA · Seen Dec 2024
  • Maximum Sum of Non-Adjacent ElementsOA · Seen Sep 2024
  • Return the Sentence with the Most WordsOA · Seen Sep 2024

Similar questions at other companies

  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • First Non-Repeating CharacterAmazon · OA · ONSITE INTERVIEW
  • Maximum Ones After K OperationsGoldman Sachs · OAGoldman Sachs interview questions
  • Total Each Letter's Count in an Encoded StringIBM · OAIBM interview questions
  • Find Words That Can Be Formed by CharactersTabaPay · OA
  • Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
  • Count Palindrome Addition ChoicesThe D.E. Shaw Group · OAThe D.E. Shaw Group interview questions
  • Count Palindrome Addition ChoicesHudson River Trading · OAHudson River Trading interview questions
  • Count Phrases Formed by Anagram ReplacementWells Fargo · OAWells Fargo interview questions
  • Count Substrings With Identical CharactersVirtu Financial · OAVirtu Financial interview questions

Interview reports that mention this question

  • LSEG Graduate Technology OA and Interviews: 7 Experiences
All LSEG interview questionsSee LSEG hiring insights
Saved
class Solution {
    public int maximumSentenceWords(String text) {
        // write your code here
    }
}
Checking account…