Code Room
CodingMediumcod-g798
Subject RecursionLevel Mid–Senior~25 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

Given a `word`, return all of its generalized abbreviations. An abbreviation replaces any subset of the characters with a single number equal to how many were replaced, where any run of consecutive replaced characters merges into one number. For example 'word' yields abbreviations like 'word', '1ord', 'w1rd', 'wor1', '2rd', '4', and so on. Return the full list sorted lexicographically. 0 <= len(word) <= 12.

Implement
generate_abbreviations(word: str) → list[str]
Examples
in["word"]out["1o1d","1o2","1or1","1ord","2r1","2rd","3d","4","w1r1","w1rd","w2d","w3","wo1d","wo2","wor1","word"]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.