FastPrepValid Word Abbreviation

Valid Word Abbreviation

Meta logoMeta● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Given a lowercase word and an abbreviation, determine whether the abbreviation represents the word.

A positive decimal number skips that many consecutive characters. A number may not start with 0.

Function

validWordAbbreviation(word: String, abbreviation: String) → boolean

Examples

Example 1

word = "internationalization"abbreviation = "i12iz4n"return = true

The numeric parts skip 12 and 4 characters, and every literal matches.

Example 2

word = "apple"abbreviation = "a2e"return = false

After skipping two characters, the abbreviation expects e where the word has l.

Constraints

  • 1 <= word.length, abbreviation.length <= 100
  • word contains lowercase English letters.
  • abbreviation contains lowercase English letters and digits.

More Meta problems

See Meta hiring insights
public boolean validWordAbbreviation(String word, String abbreviation) {
    // Write your code here.
}
word"internationalization"
abbreviation"i12iz4n"
expectedtrue
Checking account…