Return Word Frequencies in Alphabetical Word Order

Read the full interview experience this question came from →

Quick Overview

Count occurrences of distinct words and return only their frequencies in alphabetical word order. Use a map plus sorted keys, with explicit case sensitivity and attention to empty inputs and string costs.

Return Word Frequencies in Alphabetical Word Order

Company: Abridge

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Online Assessment

Given a list of words, count each distinct word and return a list of counts ordered alphabetically by the corresponding distinct words. The output contains counts only, not word-count pairs. ### Constraints and Clarifications No numerical size bounds are given. For this practice interface, words are case-sensitive strings and alphabetical order means ordinary lexicographic order of their character values; no lowercasing, punctuation removal, or locale collation is applied. An empty list returns an empty list. These comparison choices clarify the interface rather than add reported preprocessing requirements. ### Example For ["pear", "apple", "pear", "banana", "apple", "pear"], the distinct words in order are ["apple", "banana", "pear"], so return [2, 1, 3]. This example illustrates the specified count ordering. ### What a Strong Answer Covers Use a frequency map, sort distinct words rather than frequency values, and construct the output in that key order. Account for repeated words, an empty input, and string comparison costs. ### Follow-up Questions - Why does sorting the counts themselves answer a different question? - How would the requirements change if matching were case-insensitive?

Overview: Count occurrences of distinct words and return only their frequencies in alphabetical word order. Use a map plus sorted keys, with explicit case sensitivity and attention to empty inputs and string costs.

Read the full Abridge Software Engineer interview experience this question came from

Abridge logo
Abridge
Oct 31, 2026
mediumSoftware EngineerOnline AssessmentCoding & Algorithms
0
0

Given a list of words, count each distinct word and return a list of counts ordered alphabetically by the corresponding distinct words. The output contains counts only, not word-count pairs.

Constraints and Clarifications

No numerical size bounds are given. For this practice interface, words are case-sensitive strings and alphabetical order means ordinary lexicographic order of their character values; no lowercasing, punctuation removal, or locale collation is applied. An empty list returns an empty list. These comparison choices clarify the interface rather than add reported preprocessing requirements.

Example

For ["pear", "apple", "pear", "banana", "apple", "pear"], the distinct words in order are ["apple", "banana", "pear"], so return [2, 1, 3]. This example illustrates the specified count ordering.

What a Strong Answer Covers Guidance

Use a frequency map, sort distinct words rather than frequency values, and construct the output in that key order. Account for repeated words, an empty input, and string comparison costs.

Follow-up Questions Guidance

  • Why does sorting the counts themselves answer a different question?
  • How would the requirements change if matching were case-insensitive?