Valid Word Abbreviation

Try to solve the Valid Word Abbreviation problem.

Statement

Given a string word and an abbreviation abbr, return TRUE if the abbreviation matches the given string. Otherwise, return FALSE.

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

  • "cal3ar" ("cal end ar" skipping three characters "end" from the word "calendar" still matches the provided abbreviation)

  • "c6r" ("c alenda r" skipping six characters "alenda" from the word "calendar" still matches the provided abbreviation)

The following are not valid abbreviations:

  • "c06r" (has leading zeroes)

  • "cale0ndar" (replaces an empty string)

  • "c24r" ("c al enda r" the replaced substringsA substring is a contiguous non-empty sequence of characters within a string. are adjacent)

Constraints:

  • 1≤1 \leq word.length ≤20\leq 20

  • word consists of only lowercase English letters.

  • 1≤1 \leq abbr.length ≤10\leq 10

  • abbr consists of lowercase English letters and digits.

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

Examples

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.