> ## 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.

# Letter Case Permutation Python Solution

> Tested Python solution for LeetCode 784 with 18 pytest cases. Generate a practice environment with lcpy.

LeetCode 784, [Medium](/catalog/medium). Topics: [String](/catalog/topics/string), [Backtracking](/catalog/topics/backtracking), [Bit Manipulation](/catalog/topics/bit-manipulation). [View on LeetCode](https://leetcode.com/problems/letter-case-permutation/description/).

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

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 784   # by problem number
lcpy gen -s letter_case_permutation   # by problem name
```

## Problem

Given a string `s`, you can transform every letter individually to be lowercase or uppercase to create another string.

Return a list of all possible strings we could create. Return the output in **any order**.

### Examples

```
Input: s = "a1b2"
Output: ["a1b2","a1B2","A1b2","A1B2"]
```

```
Input: s = "3z4"
Output: ["3z4","3Z4"]
```

### Constraints

* `1 <= s.length <= 12`
* `s` consists of lowercase English letters, uppercase English letters, and digits.

## Solution

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

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n * 2^k) where k is the number of letters
    # Space: O(n * 2^k) for the output
    def letter_case_permutation(self, s: str) -> list[str]:
        results: list[str] = [""]

        for ch in s:
            if ch.isalpha():
                results = [prefix + alt for prefix in results for alt in (ch.lower(), ch.upper())]
            else:
                results = [prefix + ch for prefix in results]
        return results
```

## Complexity

| Time | Space |
| - | - |
| O(n \* 2^k) where k is the number of letters | O(n \* 2^k) for the output |

## Tags


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