List Every Abbreviation of a Username by Collapsing Letters
Last updated: November 29, 2026
Quick Overview
Generate every abbreviation of a word where any set of non-adjacent runs of letters may be replaced by their length. For example, word can become w2d, 4, or 1o1d.
Google
Coding & Algorithms
Software Engineer
Software Engineer
Technical Screen
Coding & Algorithms
Medium
0
0
0 solved
Generate every abbreviation of a word where any set of non-adjacent runs of letters may be replaced by their length. For example, word can become w2d, 4, or 1o1d.
A Google technical screen that looks simple but trips people on the no-adjacent-numbers rule. The interviewer checks that the recursion state carries a pending count so consecutive abbreviated letters merge into one number.
What the Interviewer Expects
- Carries a running count of abbreviated letters in the recursion state
- Flushes the count only when keeping a letter or at the end
- Produces exactly 2^n abbreviations
- Gives O(n * 2^n) time
- Explains how to check if a given abbreviation matches a word
Key Topics to Cover
Backtracking
String generation
Recursion state
Bitmask enumeration
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Given a word and an abbreviation, check whether they match.
- Find the shortest abbreviation of a target that matches no word in a dictionary.
- How would you order abbreviations by length?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: a word of lowercase letters, length n up to about 15.
- Output: every abbreviation, where each letter is either kept or abbreviated, and runs of abbreviated letters appear as one decimal coun...
High-Level Design
At index i, two choices:
- Abbreviate
word[i]: increment the pending count and move on, without writing anything yet. - Keep
word[i]: first flush the pending count (if positive) as digits, then...
Submit Your Answer
Markdown supported