Search⌘ K
AI Features

Valid Word Abbreviation

Understand how to determine if a given abbreviation correctly represents a word by replacing substrings with their lengths. This lesson explores the two pointers method to efficiently compare the original word and its abbreviation while adhering to constraints like no leading zeros and non-empty substrings.

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" skipping three characters "end" from the word "calendar" still matches the provided abbreviation)

  • "c6r" ("c + alenda [length = 6] + r" skipping six characters "alenda" from the word "calendar" still matches the provided abbreviation)

The word "internationalization" can also be abbreviated as ...