Validate abbreviations and brackets
MetaSite Reliability Engineer · Technical ScreenLast updated
This question evaluates proficiency in string parsing, pattern validation, and algorithmic correctness, covering abbreviation interpretation and bracket balancing while requiring careful handling of edge cases and input constraints.
The coding round included two short implementation problems:
- Abbreviation validation
Given a lowercase word
wordand a stringabbr, determine whetherabbris a valid abbreviation ofword.
- Letters in
abbrmust match the corresponding letters inword. - A positive integer in
abbrmeans skipping that many characters inword. - Numbers cannot have leading zeros.
- The abbreviation is valid only if it consumes the entire word exactly.
Example:
word = "internationalization",abbr = "i12iz4n"->trueword = "apple",abbr = "a2e"->false
- Balanced bracket validation
Given a string
scontaining only the characters(,),[,],{, and}, return whether the brackets are balanced.
- Every opening bracket must be closed by the same type of bracket.
- Brackets must be closed in the correct order.
- An empty string is considered valid.
Example:
s = "()[]{}"->trues = "([)]"->false
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.