Search⌘ K
AI Features

Solution: Valid Word Abbreviation

Explore the two pointers technique to determine if a given abbreviation correctly matches a word by iterating over both strings. Understand how to handle skipped characters indicated by numbers in the abbreviation, check for valid formatting, and ensure character matches. This lesson helps you implement an efficient O(n) time complexity solution to validate word abbreviations.

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" ...