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
Given a list of words, count each distinct word. Return a list containing only the counts, ordered by the corresponding distinct words in ordinary lexicographic order of their character values. Words are case-sensitive strings. Do not lowercase, remove punctuation, normalize, or use locale-specific collation. An empty input returns an empty list.
Example: ["pear", "apple", "pear", "banana", "apple", "pear"] has distinct words in order ["apple", "banana", "pear"], so return [2, 1, 3].
Constraints
- Words are case-sensitive strings; no input-size bound is reported.
- Sort distinct words lexicographically by character values, without locale collation or normalization.
- Return counts only, in distinct-word order.
- An empty word list returns [].
Examples
Input: ([],)
Expected Output: []
Explanation: No distinct words produce no counts.
Input: (['x'],)
Expected Output: [1]
Explanation: The one word appears once.
Hints
- The requested order belongs to the words, not the counts.
- A repeated word contributes to one count at each of its positions.