> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Long Pressed Name Python Solution with Tests

> Tested Python solution for LeetCode 925 with 25 pytest cases. Generate a practice environment with lcpy.

LeetCode 925, [Easy](/catalog/easy). Topics: [Two Pointers](/catalog/topics/two-pointers), [String](/catalog/topics/string). [View on LeetCode](https://leetcode.com/problems/long-pressed-name/description/).

Generate this problem as a practice environment: tested reference solution, 25 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 925   # by problem number
lcpy gen -s long_pressed_name   # by problem 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.

### Examples

```
Input: name = "alex", typed = "aaleex"
Output: true
Explanation: 'a' and 'e' in 'alex' were long pressed.
```

```
Input: name = "saeed", typed = "ssaaedd"
Output: false
Explanation: 'e' must have been pressed twice, but it was not in the typed output.
```

### Constraints

* 1 \<= name.length, typed.length \<= 1000
* name and typed consist of only lowercase English letters.

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/long_pressed_name/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/long_pressed_name/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(len(name) + len(typed))
    # Space: O(1)
    def is_long_pressed_name(self, name: str, typed: str) -> bool:
        i = 0
        for j, ch in enumerate(typed):
            if i < len(name) and name[i] == ch:
                i += 1
            elif j == 0 or ch != typed[j - 1]:
                return False
        return i == len(name)
```

## Complexity

| Time | Space |
| - | - |
| O(len(name) + len(typed)) | O(1) |

## Tags


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.