FastPrepWord Frequency in a Large Text
Problems/Word Frequency in a Large Text

Word Frequency in a Large Text

Robinhood logoRobinhood● EasyFULLTIMEPHONE SCREEN
QuestionFunctionExamples

Problem statement

Source note: The interview report provided the complete word-splitting, case, punctuation, frequency, and sorting rules plus one example. The original function signature and numeric constraints were not included.

Given a large string text, split it into words using punctuation characters and whitespace as separators.

Result Rules

  • Matching is case-insensitive.
  • Punctuation is not part of a word.
  • Return each result as "word frequency" using the lowercase word.
  • Sort by descending frequency. When frequencies are equal, sort the words lexicographically.

Function

wordFrequency(text: String) → String[]

Examples

Example 1

text = "hello world, hello computer"return = ["hello 2","computer 1","world 1"]

hello appears twice. computer and world appear once, so their tie is resolved lexicographically.

More Robinhood problems

  • Top Ten Most Frequent Words in a BookPHONE SCREEN · Seen Oct 2026
  • Fractional Share Inventory FlatteningPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Unique Transitive Dependent CountsPHONE SCREEN · Seen Sep 2026
All Robinhood interview questionsSee Robinhood hiring insights
Saved
public String[] wordFrequency(String text) {
  // write your code here
}
Checking account…