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

# Strobogrammatic Number II Python Solution

> Tested Python solution for LeetCode 247 with 14 pytest cases. Generate a practice environment with lcpy.

LeetCode 247, [Medium](/catalog/medium). Topics: [Recursion](/catalog/topics/recursion), [Array](/catalog/topics/array), [String](/catalog/topics/string). [View on LeetCode](https://leetcode.com/problems/strobogrammatic-number-ii/description/).

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

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

## Problem

Given an integer `n`, return all the **strobogrammatic numbers** that are of length `n`. You may return the answer in **any order**.

A **strobogrammatic number** is a number that looks the same when rotated `180` degrees (looked at upside down).

### Examples

```
Input: n = 2
Output: ["11","69","88","96"]
```

```
Input: n = 1
Output: ["0","1","8"]
```

### Constraints

* `1 <= n <= 14`

## Solution

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

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(2^n)
    # Space: O(2^n)
    def find_strobogrammatic(self, n: int) -> list[str]:
        def build(length: int) -> list[str]:
            if length == 0:
                return [""]
            if length == 1:
                return ["0", "1", "8"]
            results: list[str] = []
            for middle in build(length - 2):
                for left, right in ("11", "88", "69", "96"):
                    results.append(left + middle + right)
                if length != n:
                    results.append("0" + middle + "0")
            return results

        return build(n)
```

## Complexity

| Time | Space |
| - | - |
| O(2^n) | O(2^n) |

## Tags

[NeetCode All](/catalog/neetcode).


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