FastPrepLexicographic Word Frequencies
Problems/Lexicographic Word Frequencies

Lexicographic Word Frequencies

Upstart logoUpstart● EasyFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source asks for word counts in alphabetical order but omits token normalization, duplicate representation, output shape, and bounds. The judged core task matches the visible source at about 92%.

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 1 through 40.
  • Every word contains only lowercase English letters.
  • The total number of input characters is at most 10^6.

More Upstart problems

  • Babysitter Quote with Hourly RatesONSITE INTERVIEW · Seen Oct 2026
  • Maximum SubarrayONSITE INTERVIEW · Seen Oct 2026
  • Buffet Day GainsOA · Seen Sep 2026
All Upstart interview questionsSee Upstart hiring insights
Saved
class Solution {
    public String[][] wordFrequencies(String[] words) {
        // Write your code here.
    }
}
Checking account…