#K46202. Minimum Operations to Make Anagrams
Minimum Operations to Make Anagrams
Minimum Operations to Make Anagrams
Given two strings a and b of length n, you are allowed to modify the string a by performing operations. In each operation, you can replace any character in a with any other lowercase English letter. The goal is to make a an anagram of b.
Recall that two strings are anagrams if and only if for every letter, the frequency in both strings is the same. Let the frequency of the character corresponding to index i (with i=0 for 'a', i=1 for 'b', etc.) in a string be denoted by \(f_i(\cdot)\). Then, the minimum number of operations required is:
\(\sum_{i=0}^{25} \max(0, f_i(b) - f_i(a))\)
Help determine the minimum number of operations needed for each test case.
inputFormat
The first line contains an integer T
, the number of test cases.
Each test case consists of three lines:
- First line contains an integer
n
representing the length of the strings. - The second line contains the string
a
. - The third line contains the string
b
.
You can assume that both a
and b
consist only of lowercase English letters and have length n
.
outputFormat
For each test case, output a single line containing one integer: the minimum number of operations required to make a
an anagram of b
.
2
3
abc
bca
4
abcd
dcba
0
0
</p>