Problem · String
Lexicographic Word Frequencies
Learn this problemProblem statement
Given an array of words words, count each distinct word and return the counts in lexicographic order.
Words contain lowercase English letters and comparisons are exact. Return a two-dimensional string array where every row is [word, decimalCount]. Return an empty array when the input is empty.
Function
wordFrequencies(words: String[]) → String[][]Examples
Example 1
words = ["pear","apple","pear","banana","apple","apple"]return = [["apple","3"],["banana","1"],["pear","2"]]apple appears three times, banana once, and pear twice. The rows are ordered by word.
Example 2
words = []return = []An empty input has no frequency rows.
Example 3
words = ["zoo","ant","zoo","bee","ant"]return = [["ant","2"],["bee","1"],["zoo","2"]]The distinct words are returned in ascending lexicographic order with decimal counts.
Constraints
0 <= words.length <= 200000- Every word has length from
1through40. - Every word contains only lowercase English letters.
- The total number of input characters is at most
10^6.
More Upstart problems
- Add Drama to Text GroupsOA · Seen Jul 2026
- Minimum Absolute Pair DifferenceOA · Seen Jul 2026
- Sum Multiples of 3, 5, or 7 Below NOA · Seen Jul 2026
- Coordinate Bounding BoxOA · Seen Jul 2026
- Increase Exclamations and Convert PeriodsOA · Seen Jul 2026
- Interleave Equal-Length Strings by ColumnOA · Seen Jul 2026
- Scale Ingredient QuantitiesOA · Seen Jul 2026
- Bounding Box from CoordinatesOA · Seen May 2026