Validate a Shortened Handle Against the Full Username
Last updated: November 29, 2026
Quick Overview
An abbreviation replaces some non-adjacent runs of characters with their lengths, for example "i12iz4n" for "internationalization". Given a word and an abbreviation, return whether the abbreviation is valid for the word; numbers may not have leading zeros.
Meta
November 29, 20260
0
0 solved
An abbreviation replaces some non-adjacent runs of characters with their lengths, for example "i12iz4n" for "internationalization". Given a word and an abbreviation, return whether the abbreviation is valid for the word; numbers may not have leading zeros.
A two-pointer string parsing question in the style of Meta's first screen problem. The interviewer is mostly checking careful handling of multi-digit numbers, leading zeros, and running past the end of the word.
What the Interviewer Expects
- Parses multi-digit numbers rather than single digits
- Rejects numbers with a leading zero, including "0"
- Checks that both pointers finish exactly at the end
- Avoids building substrings in a loop
- Writes tests for the tricky failure cases
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you generate all valid abbreviations of a word?
- What if the abbreviation could also contain wildcards?
- How would you find the shortest abbreviation that is unique among a dictionary of handles?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: word of lowercase letters, abbr of lowercase letters and digits. A number means skip that many characters. Leading zeros are invalid and a run of zero is invalid. Output a boolean. O(len(w...
High-Level Design
Walk i over the word and j over the abbreviation. If abbr[j] is a letter it must equal word[i], then both advance. If it is a digit, reject a 0 immediately (that catches both leading zeros a...