Ctrl K

Sticky Keyboard

Easy
Your friend types their name name on an old keyboard. Sometimes a key sticks, and the letter comes out several times in a row instead of once. The keyboard makes no other mistakes: letters are never lost, swapped or added out of nowhere. You see what ended up on the screen, the string typed. Return True if it could have come from typing name (possibly with no sticking at all), and False otherwise.
Example 1
name='mila', typed='mmiilaaa' → True

The m, i and a keys stuck: every letter of the name appears at least as many times as needed, and nothing extra was typed.

Example 2
name='anna', typed='ana' → False

The name has two n's in a row, but only one was typed. A sticky key can add letters, never drop them.

Example 3
name='leo', typed='leeoz' → False

There is no z in the name at all, so no sticky key could have produced it.

Constraints
  • 1 ≤ len(name), len(typed) ≤ 1000
  • name and typed consist of lowercase English letters
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
name='mila', typed='mmiilaaa'
Expected
True

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