Problem · String

Word Frequency in a Large Text

Learn this problem
EasyRobinhoodFULLTIMEPHONE SCREEN

Problem statement

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.

drafts saved locally
public String[] wordFrequency(String text) {
  // write your code here
}
text"hello world, hello computer"
expected["hello 2", "computer 1", "world 1"]
checking account