Long Pressed Name - Problem
Your friend is typing his name into a keyboard. Sometimes, when typing a character c, the key might get long pressed, and the character will be typed 1 or more times.
You examine the typed characters of the keyboard. Return true if it is possible that it was your friend's name, with some characters (possibly none) being long pressed.
Input & Output
Example 1 — Basic Long Press
$
Input:
name = "alex", typed = "aaleex"
›
Output:
true
💡 Note:
The 'a' and 'e' were long pressed, resulting in extra characters, but the sequence matches the name
Example 2 — Wrong Character
$
Input:
name = "saeed", typed = "ssaaedd"
›
Output:
false
💡 Note:
The 'e' in typed was long pressed, but we're missing one 'e' that should appear after 'a'
Example 3 — Perfect Match
$
Input:
name = "leelee", typed = "lleeelee"
›
Output:
true
💡 Note:
All characters match with some long presses on 'l' and 'e'
Constraints
- 1 ≤ name.length ≤ 1000
- 1 ≤ typed.length ≤ 1000
- name and typed consist of only lowercase English letters
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code