FastPrepReturn the Sentence with the Most Words
Problems/Return the Sentence with the Most Words

Return the Sentence with the Most Words

LSEG logoLSEG● EasyFULLTIMEOA

Updated Oct 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The reported sentence-return task and comma/period/question/exclamation delimiters match at about 90%. Tie-breaking, spacing, empty-input behavior and bounds are exercise conventions.

Split text at each comma ,, period ., question mark ? or exclamation mark !. The final part is also a sentence, even without a trailing delimiter.

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

Return the sentence with the most words. Break ties by choosing the earliest sentence. Remove surrounding spaces from the returned sentence, preserve its internal spaces, and exclude its delimiter. If there are no words, return the empty string.

Function

sentenceWithMostWords(text: String) → String

Examples

Example 1

text = "Read,Try this now!Keep going."return = "Try this now"

The nonempty parts have 1, 3 and 2 words. Return the three-word sentence without its exclamation mark.

Example 2

text = "One two.Three four"return = "One two"

Both sentences have two words, so return the earlier one.

Example 3

text = " , . ? ! "return = ""

The parts contain only spaces, so there is no sentence with a word.

Constraints

  • 0 <= text.length <= 100000.
  • text contains only English letters, ordinary spaces, commas, 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
  • Maximum Word Count in a SentenceOA · 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

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 String sentenceWithMostWords(String text) {
        // write your code here
    }
}
Checking account…