Count Word Frequencies
Problem statement
Given an array of lowercase words, count how many times each distinct word appears.
Return entries of the form "word|count", ordered lexicographically by word. Return an empty array when the input is empty.
Function
countWordFrequencies(words: String[]) → String[]Examples
Example 1
words = ["apple","pear","apple","banana","pear","apple"]return = ["apple|3","banana|1","pear|2"]Counts are serialized in lexical word order.
Example 2
words = []return = []No input words produce no frequency entries.
Example 3
words = ["z","z","z"]return = ["z|3"]One distinct word produces one entry.
Constraints
0 <= words.length <= 100000.- Every word contains between
1and30lowercase English letters.