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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
Strings
Two pointers
Parsing
Edge cases
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported