Valid Word Abbreviation
Try to solve the Valid Word Abbreviation problem.
We'll cover the following
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 are adjacent)substrings A substring is a contiguous non-empty sequence of characters within a string.
Constraints:
word.length
word
 consists of only lowercase English letters.abbr.length
abbr
 consists of lowercase English letters and digits.All the integers inÂ
abbr
 will fit in a–bit integer.
Examples
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.