Problem
Ask
Submissions

Problem: Valid Word Abbreviation

easy
15 min
Explore how to verify if an abbreviation correctly represents a word by learning to use the two-pointer approach. Understand the rules for numeric replacements and matching characters, and practice implementing a solution that identifies valid abbreviations step by step.

Statement

A string can be abbreviated by replacing any number of non-adjacent, non-empty substrings with their respective lengths. The numeric replacements must not contain leading zeros.

Given a string word and an abbreviation abbr, determine whether abbr is a valid abbreviation of word.

The abbreviation abbr consists of lowercase English letters and numeric values. Each numeric value in abbr represents the number of characters skipped in word. Letters in abbr must match the corresponding characters in word exactly. The abbreviation is valid if and only if it fully accounts for every character in word from left to right with no characters remaining or missing.

Note: A numeric value in abbr must not have leading zeros (e.g., "01" is invalid). A value of "0" is also invalid since it would represent replacing an empty substring.

Constraints:

  • 11 \leq word.length 20\leq 20

  • word consists of only lowercase English letters.

  • 11 \leq abbr.length 10\leq 10

  • abbr consists of lowercase English letters and digits.

  • All integers in abbr will fit in a 3232-bit integer.

Problem
Ask
Submissions

Problem: Valid Word Abbreviation

easy
15 min
Explore how to verify if an abbreviation correctly represents a word by learning to use the two-pointer approach. Understand the rules for numeric replacements and matching characters, and practice implementing a solution that identifies valid abbreviations step by step.

Statement

A string can be abbreviated by replacing any number of non-adjacent, non-empty substrings with their respective lengths. The numeric replacements must not contain leading zeros.

Given a string word and an abbreviation abbr, determine whether abbr is a valid abbreviation of word.

The abbreviation abbr consists of lowercase English letters and numeric values. Each numeric value in abbr represents the number of characters skipped in word. Letters in abbr must match the corresponding characters in word exactly. The abbreviation is valid if and only if it fully accounts for every character in word from left to right with no characters remaining or missing.

Note: A numeric value in abbr must not have leading zeros (e.g., "01" is invalid). A value of "0" is also invalid since it would represent replacing an empty substring.

Constraints:

  • 11 \leq word.length 20\leq 20

  • word consists of only lowercase English letters.

  • 11 \leq abbr.length 10\leq 10

  • abbr consists of lowercase English letters and digits.

  • All integers in abbr will fit in a 3232-bit integer.