#C11762. String Shuffle Game
String Shuffle Game
String Shuffle Game
You are given two strings s
and t
of length n
. The goal of the game is to determine the minimum and maximum possible number of positions where the characters of s
differ from the corresponding characters of t
after you are allowed to arbitrarily shuffle the characters in each string.
In other words, let the two strings be re-arranged independently, and then let d be the number of indices i
such that s[i] ≠ t[i]
. You need to compute the minimum and maximum values of d possible.
The maximum value of d is always n
, since you could, for example, arrange them so that no character matches at the same position.
The minimum value is computed as follows. Let \( \text{common} = \sum_{c}\min(\text{count}_s(c), \text{count}_t(c)) \) be the total number of characters that can be paired between the two strings. Then the minimum number of differing positions is given by:
[ \text{min_diff} = n - \text{common} ]
Your task is to write a program that, given n
, s
, and t
, outputs the value of min_diff
and max_diff
(which is n
) separated by a space.
inputFormat
The input is read from stdin and consists of three lines:
- The first line contains an integer
n
— the length of the strings. - The second line contains the string
s
. - The third line contains the string
t
.
outputFormat
Output to stdout two space-separated integers: the minimum and maximum possible number of positions at which the two strings differ after shuffling.
In other words, output:
[ (n - \text{common}) \quad n ]
where \( \text{common} = \sum_{c}\min(\text{count}_s(c), \text{count}_t(c)) \).
## sample3
abc
cab
0 3
</p>