#K43492. Taco's Minimum Swaps Challenge
Taco's Minimum Swaps Challenge
Taco's Minimum Swaps Challenge
You are given two strings s
and t
of equal length. Your task is to determine the minimum number of swap operations required to transform s
into t
. In one swap operation, you can choose two positions in s
(they can be the same or different) and swap the characters at those positions.
The transformation is only possible if s
and t
have the same overall frequency of each character. If they do not, output -1
.
Note:
- The input strings consist of lowercase letters only.
- The length of the strings satisfies \(1 \leq |s| = |t| \leq 10^6\).
- Each swap operation can potentially fix two mismatched positions.
Example:
Input: abcd cdab</p>Output: 2
inputFormat
The input is given via stdin and consists of two lines:
- The first line contains the string
s
. - The second line contains the string
t
.
outputFormat
Output a single integer — the minimum number of swap operations required to transform s
into t
. If it is impossible to do so, output -1
.
The output should be written to stdout.
## sampleabcd
cdab
2