FastPrepRank Words by Frequency
Problems/Rank Words by Frequency

Rank Words by Frequency

Datadog logoDatadog● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks to order words by their occurrence counts. Token boundaries, case normalization, ties, output encoding, empty input, and bounds are specified for practice. The core task matches the report at about 85%.

Count the frequency of every word in paragraph and return one entry per distinct word, ordered by decreasing frequency. Break equal-frequency ties by increasing lexicographic word order.

A word is a maximal consecutive run of English letters A-Z or a-z. Every other character separates words. Convert words to lowercase before counting. Each output entry has the form word:count, with an ordinary decimal count and no spaces. Return an empty array when there are no words.

Function

rankWordFrequencies(paragraph: String) → String[]

Examples

Example 1

paragraph = "pear PEAR, apple apple APPLE. Kiwi"return = ["apple:3","pear:2","kiwi:1"]

Ignoring case, apple appears three times, pear twice, and kiwi once. Sort by those frequencies from largest to smallest.

Example 2

paragraph = "red blue red BLUE"return = ["blue:2","red:2"]

Both words occur twice. The frequency tie is resolved lexicographically, so blue comes before red.

Example 3

paragraph = "...123..."return = []

There is no run of English letters, so there are no words to rank.

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[] rankWordFrequencies(String paragraph) {
    // Write your code here.
}
Checking account…