The Generalized Abbreviation interview question asks you to generate all possible generalized abbreviations of a given word. An abbreviation is created by replacing any number of non-overlapping, non-adjacent substrings with their lengths. For example, "word" can be abbreviated as "4", "3d", "w3", "w2d", "w1r1", etc. You need to return a list of all valid abbreviations.
Google uses this Backtracking interview pattern to test a candidate's ability to explore a full state space (generating combinations). It evaluates your recursion skills, particularly how you manage state strings and counts during branching. It's a classic subset-generation problem with formatting constraints.
This problem is solved using Backtracking / Recursion. At each character in the string, you have two choices:
Word: "ab"
"ab"."a1"."1b"."2".
Final output: ["ab", "a1", "1b", "2"].string + char inside the recursive call creates many temporary objects. Using a StringBuilder and backtracking (undoing the append) is more memory efficient.count when the recursion reaches the end of the word.This problem can also be solved using Bit Manipulation. Since there are combinations, you can loop from to . For each number, treat the bit as a flag: if 1, abbreviate the character; if 0, keep it. This avoids recursion entirely and is highly impressive to interviewers.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Generate Binary Strings Without Adjacent Zeros | Medium | Solve | |
| Letter Case Permutation | Medium | Solve | |
| Maximum Length of a Concatenated String with Unique Characters | Medium | Solve | |
| Minimum Unique Word Abbreviation | Hard | Solve | |
| Split Array into Fibonacci Sequence | Medium | Solve |