Check Whether Repeated Keystrokes Can Produce a Typed Name
Quick Overview
Check Whether Repeated Keystrokes Can Produce a Typed Name. Each character of name must be typed in order, but a long press may repeat that character one or more times.
Check Whether Repeated Keystrokes Can Produce a Typed Name
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Other
### Problem
Each character of `name` must be typed in order, but a long press may repeat that character one or more times. Return whether `typed` could result from those presses, with zero or more long presses. No original character may be omitted, replaced, or moved.
```cpp
class Solution {
public:
bool isLongPressedName(string name, string typed);
};
```
### Examples
**Example 1:**
```text
Input: name = "mira", typed = "mmiirraa"
Output: true
Explanation: Each original character has been repeated twice in the same order.
```
**Example 2:**
```text
Input: name = "book", typed = "bok"
Output: false
Explanation: The two consecutive original o characters require at least two typed o characters, but only one appears.
```
### Constraints
- `1 <= name.length,typed.length <= 1000`.
- Both strings contain only lowercase English letters.
### Contract considerations
Only lowercase English letters occur, and both strings are nonempty.
```hint Read the boundary condition
Long pressing expands runs; it cannot shrink them or change their order.
```
### Boundary reminders
Only lowercase English letters occur, and both strings are nonempty.
Overview: Check Whether Repeated Keystrokes Can Produce a Typed Name. Each character of name must be typed in order, but a long press may repeat that character one or more times.
Check Whether Repeated Keystrokes Can Produce a Typed Name
Google
Jun 24, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0
Problem
Each character of name must be typed in order, but a long press may repeat that character one or more times. Return whether typed could result from those presses, with zero or more long presses. No original character may be omitted, replaced, or moved.
class Solution {
public:
bool isLongPressedName(string name, string typed);
};
Examples
Example 1:
Input: name = "mira", typed = "mmiirraa"
Output: true
Explanation: Each original character has been repeated twice in the same order.
Example 2:
Input: name = "book", typed = "bok"
Output: false
Explanation: The two consecutive original o characters require at least two typed o characters, but only one appears.
Constraints
1 <= name.length,typed.length <= 1000
.
Both strings contain only lowercase English letters.
Contract considerations
Only lowercase English letters occur, and both strings are nonempty.
Boundary reminders
Only lowercase English letters occur, and both strings are nonempty.