FastPrepFind the Most Frequent Word
Problems/Find the Most Frequent Word

Find the Most Frequent Word

Datadog logoDatadog● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for the most frequent word in a string and mentions a map and priority queue. Token boundaries, case handling, ties, empty input, and bounds are specified for practice. The core task matches the report at about 80%.

Return the word that occurs most often in paragraph. A word is a maximal consecutive run of English letters A-Z or a-z; every other character separates words.

Count words without regard to case and return the chosen word in lowercase. If several words share the largest count, return the lexicographically smallest one. Return the empty string when the paragraph has no words.

Function

mostFrequentWord(paragraph: String) → String

Examples

Example 1

paragraph = "pear APPLE pear apple apple"return = "apple"

After case normalization, apple occurs three times and pear twice. Return apple.

Example 2

paragraph = "red blue RED BLUE"return = "blue"

Both words occur twice. The tie rule chooses the lexicographically smaller word, blue.

Example 3

paragraph = "42!?"return = ""

There are no English-letter words, so return the empty string.

Constraints

  • 0 <= paragraph.length <= 10000
  • Every character is printable ASCII, a tab, a carriage return, or a line feed.

More Datadog problems

  • Query Log MatchPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Delete a Filesystem TreePHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Grouped-Query Attention Forward PassPHONE SCREEN · Seen Jun 2026
All Datadog interview questionsSee Datadog hiring insights
Saved
public String mostFrequentWord(String paragraph) {
    // Write your code here.
}
Checking account…