#C12069. String Swap Conversion
String Swap Conversion
String Swap Conversion
You are given two strings (s) and (t) of length (n), and an integer (k) denoting the maximum allowed number of swaps. In one swap, you can exchange any two characters in the string (s). Your task is to determine whether it is possible to convert (s) into (t) using at most (k) swaps. Note that a single swap may fix two mismatched positions. Specifically, if the number of indices where (s) and (t) differ is (d), then at least (\lfloor d/2 \rfloor) swaps are needed. Also, the transformation is only possible if (s) can be rearranged to become (t) (i.e. they must have the same set of characters). Print YES
if the transformation can be done within (k) swaps; otherwise, print NO
.
inputFormat
The input consists of four lines:\n(n) — an integer representing the length of the strings.\n(s) — the source string.\n(t) — the target string.\n(k) — the maximum number of swaps allowed.
outputFormat
Output a single line containing YES
if it is possible to convert (s) to (t) using at most (k) swaps, or NO
otherwise.## sample
4
abcd
cbad
2
YES