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

# Redistribute Characters to Make All Strings

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

LeetCode 1897, [Easy](/catalog/easy). Topics: [Hash Table](/catalog/topics/hash-table), [String](/catalog/topics/string), [Counting](/catalog/topics/counting). [View on LeetCode](https://leetcode.com/problems/redistribute-characters-to-make-all-strings-equal/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 1897   # by problem number
lcpy gen -s redistribute_characters_to_make_all_strings_equal   # by problem name
```

## Problem

You are given an array of strings `words` (0-indexed).

In one operation, pick two **distinct** indices `i` and `j`, where `words[i]` is a non-empty string, and move **any** character from `words[i]` to **any** position in `words[j]`.

Return `true` if you can make every string in `words` equal using any number of operations, and `false` otherwise.

### Examples

```
Input: words = ["abc","aabc","bc"]
Output: true
Explanation: Move the first 'a' in words[1] to the front of words[2],
to make words[1] = "abc" and words[2] = "abc".
All the strings are now equal to "abc", so return true.
```

```
Input: words = ["ab","a"]
Output: false
Explanation: It is impossible to make all the strings equal using the operation.
```

### 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/redistribute_characters_to_make_all_strings_equal/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/redistribute_characters_to_make_all_strings_equal/test_solution.py):

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


class Solution:
    # Time: O(total characters)
    # Space: O(1) (at most 26 keys)
    def make_equal(self, words: list[str]) -> bool:
        n = len(words)
        counts: Counter[str] = Counter()
        for word in words:
            counts.update(word)
        return all(count % n == 0 for count in counts.values())
```

## Complexity

| Time | Space |
| - | - |
| O(total characters) | O(1) (at most 26 keys) |

## Tags

[NeetCode All](/catalog/neetcode).


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