Ctrl K

Word With Counted Gaps

Easy
In notes, words are sometimes shortened by replacing a run of consecutive letters with how many letters there were. For example, keyboard can be written as k6d, key5, k3o2d or 8, or left as it is. The rules for a short form short: - a number stands for a non-empty run of letters and has no leading zeros (so 0 and 05 are not allowed); - every digit run is read as a single number, so k33d means 33 skipped letters, not 3 and 3; - each letter in the short form must match the word's letter at that position. Given word and short, return True if short is a correct short form of word, and False otherwise.
Example 1
word="keyboard", short="k3o2d" → True

k, then 3 skipped letters eyb, then o, 2 more letters ar, and d.

Example 2
word="river", short="r3" → False

Only 3 letters are skipped after r, but 4 remain.

Example 3
word="tea", short="t02" → False

A number may not start with a zero.

Constraints
  • 1 ≤ len(word) ≤ 20, word consists of lowercase English letters
  • 1 ≤ len(short) ≤ 20, short consists of lowercase English letters and digits
  • Every number in short is less than 2³¹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsWhere the Fragment Starts EasyMirror Phrase Check EasySame When Flipped EasyFlip the Characters in Place EasyMirror the Vowels Easy
loading Python…
Input
word="keyboard", short="k3o2d"
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 181 tests on the server, hidden ones included.