Given a sentence of space-separated words, return the most frequently occurring word. Comparison is case-insensitive and the returned word must be lowercase. If several words tie for the highest count, return the one that appears first in the sentence. For a null or blank sentence, return an empty string. Assume words contain no punctuation.

Examples:

Input: sentence = 'the cat the dog the bird' Output: 'the' Explanation: 'the' appears 3 times, more than any other word Input: sentence = 'apple banana apple cherry banana apple' Output: 'apple' Explanation: 'apple' appears 3 times Input: sentence = 'one two three' Output: 'one' Explanation: All words appear once, so return the first word Input: sentence = 'Hello hello HELLO world' Output: 'hello' Explanation: Case-insensitive count makes 'hello' appear 3 times Input: sentence = '' Output: '' Explanation: A blank sentence returns an empty string
Apex Code Editor

Welcome to Lightning Challenge!

How It Works

  • • Write your solution in the code editor
  • • Connect your Salesforce org to test
  • • Submit to check if your solution passes
  • • Use hints if you get stuck

Contest Alert

🏆 #CodeEveryDay November 2026 (Nov 1–15)Sponsored by FLXBL

Contest runs November 1 - 15. Complete challenges to climb the leaderboard!

Prizes 1 & 2: Salesforce certification exam voucher — won by random drawing, where every point is a ticket. see all prizes

Only the 15 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.

Wally can't hear you

Please sign in to access the AI Assistant

Sign In