Rearrange Characters to Make Target String

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.

Note: This question is the same as 1189: Maximum Number of Balloons.

Example 1
Inputs = "ilovecodingonleetcode", target = "code"
Output2
We can make at most two copies of "code" from the available letters in s, so we return 2.
Example 2
Inputs = "abcba", target = "abc"
Output1
We can make one copy of "abc", but cannot make a second because the letter c cannot be reused.

Constraints

  • 1 <= s.length <= 100
  • 1 <= target.length <= 10
  • s and target consist of lowercase English letters.

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate