Code RoomWord abbreviations
MediumPrep Room Coding #1361

Word abbreviations

CodingAlgorithms & data structuresMid–Senior~25 min

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.

0:00 of about 25 min
InputExpectedGot
["word"]["1o1d","1o2","1or1","1ord","2r1","2rd","3d","4","w1r1","w1rd","w2d","w3","wo1d","wo2","wor1","word"]not run yetsample