Generate Every Numeric Abbreviation of a Feature Name
Last updated: November 29, 2026
Quick Overview
Return every abbreviation of a word where any set of non-overlapping, non-adjacent runs of letters is replaced by the run's length, for example ads can become 3, 2s, 1d1, a2 and so on.
Meta
November 29, 20260
0
0 solved
Return every abbreviation of a word where any set of non-overlapping, non-adjacent runs of letters is replaced by the run's length, for example ads can become 3, 2s, 1d1, a2 and so on.
Meta internal tools abbreviate long feature gate names in dashboards, which frames this binary-choice backtracking problem. The interviewer checks that you merge adjacent abbreviated letters into one count instead of producing invalid strings like 11s.
What the Interviewer Expects
- Model each letter as keep or abbreviate
- Carry a running count of skipped letters
- Flush the count only when a kept letter or the end is reached
- Never place two numbers next to each other
- Confirm there are exactly 2^n results
Key Topics to Cover
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 dictionary, find the shortest abbreviation of a target that matches no other word.
- How would you check whether a given abbreviation matches a word?
- How would you return only abbreviations of length at most k?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Word length up to 15.
- Each letter is either kept or folded into a number counting consecutive folded letters.
- Return all 2^n abbreviations in any order....
High-Level Design
Recurse over positions with the string built so far and a count of letters currently being skipped. If we abbreviate the letter, increment the count and move on. If we keep it, append the pending coun...