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

# Palindrome Permutation Python Solution

> Tested Python solution for LeetCode 266 with 15 pytest cases. Generate a practice environment with lcpy.

LeetCode 266, [Easy](/catalog/easy). Topics: [Bit Manipulation](/catalog/topics/bit-manipulation), [Hash Table](/catalog/topics/hash-table), [String](/catalog/topics/string). [View on LeetCode](https://leetcode.com/problems/palindrome-permutation/description/).

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

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

## Problem

Given a string `s`, return `true` *if a permutation of the string could form a **palindrome** and* `false` *otherwise*.

### Examples

```
Input: s = "code"
Output: false
```

```
Input: s = "aab"
Output: true
```

```
Input: s = "carerac"
Output: true
```

### Constraints

* `1 <= s.length <= 5000`
* `s` consists of only lowercase English letters.

## Solution

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

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from collections import Counter


class Solution:
    # Time: O(n)
    # Space: O(1) for the 26-letter alphabet
    def can_permute_palindrome(self, s: str) -> bool:
        counts = Counter(s)
        return sum(count % 2 for count in counts.values()) < 2
```

## Complexity

| Time | Space |
| - | - |
| O(n) | O(1) for the 26-letter alphabet |

## Tags

[NeetCode All](/catalog/neetcode).


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