Katkat

Validate word abbreviation and reconcile two abbreviations

MetaSoftware Engineer · Onsite

Last updated

Validate word abbreviation and reconcile two abbreviations evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.

Implement a function isValidAbbreviation(word: string, abbr: string) that returns true if abbr is a valid abbreviation of word, where a positive integer in abbr represents the number of letters skipped and leading zeros are invalid. Follow-ups: (a) Given two abbreviations abbr1 and abbr2, determine whether there exists at least one original word (over lowercase letters) that both could represent; if so, return true and output one possible alignment of kept/skipped positions, otherwise return false. (b) Analyze time and space complexity, and discuss how you would handle very long inputs or streaming validation.