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

# Find Common Characters Python Solution

> Tested Python solution for LeetCode 1002 with 12 pytest cases. Generate a practice environment with lcpy.

LeetCode 1002, [Easy](/catalog/easy). Topics: [Array](/catalog/topics/array), [Hash Table](/catalog/topics/hash-table), [String](/catalog/topics/string). [View on LeetCode](https://leetcode.com/problems/find-common-characters/description/).

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

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

## Problem

Given a string array `words`, return *an array of all characters that show up in all strings within the* `words` *(including duplicates)*. You may return the answer in **any order**.

### Examples

```
Input: words = ["bella","label","roller"]
Output: ["e","l","l"]
```

```
Input: words = ["cool","lock","cook"]
Output: ["c","o"]
```

### Constraints

* `1 <= words.length <= 100`
* `1 <= words[i].length <= 100`
* `words[i]` consists of lowercase English letters.

## Solution

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

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


class Solution:
    # Time: O(sum len(words))
    # Space: O(1) for the counter (26 letters)
    def common_chars(self, words: list[str]) -> list[str]:
        common = Counter(words[0])
        for word in words[1:]:
            common &= Counter(word)
        return list(common.elements())
```

## Complexity

| Time | Space |
| - | - |
| O(sum len(words)) | O(1) for the counter (26 letters) |

## Tags

[NeetCode All](/catalog/neetcode).


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