Problem · String
Word Frequency in a Large Text
Learn this problemProblem 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.