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

# Valid Anagram Python Solution with Tests

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

LeetCode 242, [Easy](https://leetcode-py.wisl.dev/catalog/easy.md). Topics: [Hash Table](https://leetcode-py.wisl.dev/catalog/topics/hash-table), [String](https://leetcode-py.wisl.dev/catalog/topics/string), [Sorting](https://leetcode-py.wisl.dev/catalog/topics/sorting). [View on LeetCode](https://leetcode.com/problems/valid-anagram/description/).

Generate this problem as a practice environment: tested reference solution, 18 [parametrized pytest cases](https://leetcode-py.wisl.dev/practice/testing.md), and a playground notebook:

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

## Problem

Given two strings `s` and `t`, return `true` if `t` is an anagram of `s`, and `false` otherwise.

### Examples

```
Input: s = "anagram", t = "nagaram"
Output: true
```

```
Input: s = "rat", t = "car"
Output: false
```

### Constraints

* 1 \<= s.length, t.length \<= 5 \* 10^4
* s and t consist of lowercase English letters.

**Follow up:** What if the inputs contain Unicode characters? How would you adapt your solution to such a case?

## Solution

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

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


class Solution:
    # Time: O(n)
    # Space: O(1) - at most 26 unique characters
    def is_anagram(self, s: str, t: str) -> bool:
        return Counter(s) == Counter(t)
```

## Complexity

| Time | Space |
| - | - |
| O(n) | O(1) - at most 26 unique characters |

## Tags

[Grind 75](https://leetcode-py.wisl.dev/catalog/grind-75.md), [Grind](https://leetcode-py.wisl.dev/catalog/grind.md), [Blind 75](https://leetcode-py.wisl.dev/catalog/blind-75.md), [NeetCode 150](https://leetcode-py.wisl.dev/catalog/neetcode-150.md), [NeetCode 250](https://leetcode-py.wisl.dev/catalog/neetcode-250.md), [NeetCode All](https://leetcode-py.wisl.dev/catalog/neetcode.md).


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