Ctrl K

Replacements to an Anagram

Medium
You get two strings of equal length, model and draft. In one move you may pick any letter in draft and replace it with any other letter. model itself cannot be changed. Return the fewest moves after which draft is an anagram of model, meaning it holds the same letters in the same quantities (the order does not matter).
Example 1
model="listen", draft="tinsel" → 0

These are already the same letters in another order, so nothing needs to change.

Example 2
model="rocket", draft="pocket" → 1

Replacing p with r is enough.

Example 3
model="aaab", draft="bbba" → 2

Two of the extra bs in draft must become as.

Constraints
  • 1 ≤ len(model) ≤ 5 · 10⁴
  • len(draft) == len(model)
  • Both strings consist of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsA Hint for a Digit Guess MediumCharacters Grouped by Count MediumMost Searched Words MediumNo Twin Letters Side by Side MediumDomain Visit Rollup Medium
loading Python…
Input
model="listen", draft="tinsel"
Expected
0

Run checks the first 3 tests in your browser. Submit checks all 72 tests on the server, hidden ones included.