Search⌘ K
AI Features

Solution: Valid Word Abbreviation

Explore how to verify if a given abbreviation matches a word by applying the two pointers technique. Learn to incrementally compare characters and handle numeric skips correctly, ensuring no leading zeros in counts. This lesson guides you through implementing an efficient O(n) solution to handle abbreviation validation with clear algorithm steps and complexity analysis.

Statement

Given a string, word, and abbreviation, abbr, return TRUE if the abbreviation matches the given string. Otherwise, return FALSE. An abbreviation can replace any non-adjacent, non-empty substrings of the original word with their lengths. Replacement lengths must not contain leading zeros.

A certain word, "calendar", can be abbreviated as follows:

  • "cal3ar" ("cal + end [length = 3] + ar" ...