---
# System prepended metadata

title: 2287. Rearrange Characters to Make Target String

---

# 2287. Rearrange Characters to Make Target String

![](https://hackmd.io/_uploads/BJOt41Nu5.png)


## mine
```python
class Solution:
    def rearrangeCharacters(self, s: str, target: str) -> int:
        
        def is_containing(current_counter, target_counter):
            for k in target_counter:
                if current_counter[k] < target_counter[k]:
                    return False
            return True
            
        target_counter = collections.Counter(target)
        s_counter = collections.Counter(s)
        ans = 0
        no_negative = True
        while no_negative:
            for k in target_counter:
                s_counter[k] -= target_counter[k]
                if s_counter[k] < 0:
                    no_negative = False
                    break
            else:
                ans += 1
        return ans
```

## better, find the limiting reagent
https://leetcode.com/problems/rearrange-characters-to-make-target-string/discuss/2085713/JavaPython-3-Minimum-multiple-of-corresponding-occurrences.
```python=
def rearrangeCharacters(self, s: str, target: str) -> int:
    target_counter = collections.Counter(target)
    s_counter = collections.Counter(s)
    return min(s_counter[c] // target_counter[c] for c in target_counter)
```