You are given two 0-indexed strings s and target. You can take some letters from s and rearrange them to form new strings.

Return the maximum number of copies of target that can be formed by taking letters from s and rearranging them.

&nbsp;
Example 1:

Input: s = "ilovecodingonleetcode", target = "code"
Output: 2
Explanation:
For the first copy of "code", take the letters at indices 4, 5, 6, and 7.
For the second copy of "code", take the letters at indices 17, 18, 19, and 20.
The strings that are formed are "ecod" and "code" which can both be rearranged into "code".
We can make at most two copies of "code", so we return 2.


Example 2:

Input: s = "abcba", target = "abc"
Output: 1
Explanation:
We can make one copy of "abc" by taking the letters at indices 0, 1, and 2.
We can make at most one copy of "abc", so we return 1.
Note that while there is an extra 'a' and 'b' at indices 3 and 4, we cannot reuse the letter 'c' at index 2, so we cannot make a second copy of "abc".


Example 3:

Input: s = "abbaccaddaeea", target = "aaaaa"
Output: 1
Explanation:
We can make one copy of "aaaaa" by taking the letters at indices 0, 3, 6, 9, and 12.
We can make at most one copy of "aaaaa", so we return 1.


&nbsp;
Constraints:


	1 &lt;= s.length &lt;= 100
	1 &lt;= target.length &lt;= 10
	s and target consist of lowercase English letters.


class Solution:
    def rearrangeCharacters(self, s: str, target: str) -> int:
        counter_s = Counter(s)
        return min(counter_s[c] // count for c,count in Counter(target).items())
class Solution
{
    public int rearrangeCharacters(String s, String target)
    {
        int[] freq = new int[26], freq2 = new int[26];
        for(char ch : s.toCharArray())
            freq[ch-'a']++;
        for(char ch : target.toCharArray())
            freq2[ch-'a']++;

        int min = Integer.MAX_VALUE;
        for(char ch : target.toCharArray())
            min = Math.min(min,freq[ch-'a']/freq2[ch-'a']);
        
        return min;
    }
}
Approach :
       => Take two map,  one to store frequency of target, and another for sentence. 
	   => Traverse over the mp(frequency of target ) and calculate the minimum frequency ratio 
	                            mn =  min(mn ,   frequency of a char in sentance / frequency of same char in target) ; 		  
										 
		Space : O(n) 
		Time : O(n)
class Solution {
public:
    int rearrangeCharacters(string s, string target) {
        unordered_map<char,int> targetFreq ; 
        for(auto a : target) {
             targetFreq[a] ++;
        }
        unordered_map<char , int> sentFreq ; 
        for(auto a : s) {
            sentFreq[a] ++ ; 
        }
        int mn = INT_MAX  ; 
        for(auto a : targetFreq ) {
             mn = min(mn , sentFreq[a.first]/a.second); 
        }
        return mn ; 
    }
};
/**
 * @param {string} s
 * @param {string} target
 * @return {number}
 */
var rearrangeCharacters = function(s, target) {
    let cnt = Number.MAX_VALUE;

    let m1 = new Map();
    for(const x of target) m1.set(x , m1.get(x)+1 || 1);

    let m2 = new Map();
    for(const x of s) m2.set(x , m2.get(x)+1 || 1);

    for(let it of m1){
        let ch = it[0];
        let x = it[1];
        let y = m2.get(ch);
        if(y === undefined) y=0;
        cnt = Math.min(cnt,Math.floor(y/x));
    }
    return cnt;
};
Rearrange Characters to Make Target String