Imagine you have a collection of letter tiles from a word game, and you want to form as many copies of a specific target word as possible!
You are given two strings: s (your available letters) and target (the word you want to form). Your goal is to determine the maximum number of complete copies of the target string you can create by rearranging the letters from s.
Key Rules:
- You can use each letter from
sonly once - You can rearrange letters in any order
- You must form complete copies of the target string
Example: If s = "ilovecodingsomuchthatticouldcodeallday" and target = "code", you need to count how many times you can spell "code" using the available letters.
Input & Output
Visualization
Time & Space Complexity
Where n is length of s and m is length of target. We iterate through target once to count, then through s once to calculate.
Where k is the number of unique characters in target (at most 26 for English alphabet).
Constraints
- 1 ≤ s.length ≤ 100
- 1 ≤ target.length ≤ 10
- s and target consist of lowercase English letters only
- target.length ≤ s.length (otherwise answer would always be 0)