Long Pressed Name

Your friend is typing their `name` on a keyboard. Sometimes a key gets long pressed, so its character is typed 1 or more extra times. Given `name` and the string `typed` that came out of the keyboard, return `true` if `typed` could be the friend's name with some characters (possibly none) long pressed.

30:00

Long Pressed Name
easy
Free written solution
Topics
Companies

Your friend is typing their name on a keyboard. Sometimes a key gets long pressed, so its character is typed 1 or more extra times. Given name and the string typed that came out of the keyboard, return true if typed could be the friend's name with some characters (possibly none) long pressed.

Example 1:
Input: {"name":"alex","typed":"aaleex"}
Output: true
Constraints:
  • 1≤name.length,typed.length≤10001 \leq \text{name.length}, \text{typed.length} \leq 1000

  • name and typed consist of only lowercase English letters.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"name":"alex","typed":"aaleex"}

i = 0 points at the next letter of name we expect, 'a'. j will walk the 6 typed keys from left to right.

name (i = next letter we expect; badge = times pressed)

i

a

1

l

2

e

3

x

typed keys (j walks them; small amber keys = held down)

0

a

1

a

2

l

3

e

4

e

5

x

i = 0 / 4
j = - / 6
long presses = 0
Variables
VariableValue
i0
DepthFunction Call
Stack empty
0/8