2-Swap

4.2

13 votes
String Algorithms, Hashing Algorithm, Algorithms
Problem

You are given two strings S and T each of length N consisting of lowercase English letters. In one operation, you can swap any two characters of S if the absolute difference between their indices is a multiple of 2. You may perform this operation any number of times. The absolute difference between indices i and j will be |ij|.

Print Yes if you can convert S into T after some operations else print No.

Input format

  • The first line contains an integer T, denoting the number of test cases.
  • The first line of each test case contains an integer N, denoting the length of the string.
  • The second line of each test case contains the string S.
  • The third line of each test case contains the string T.

Output format

For each test case, print Yes if you can convert S into T after some operations else print No in a separate line.

Constraints

1T101N105​S and T contains lowercase English letters​

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For test case 1S is already equal to T. Hence, the answer is Yes.

For test case 2S cannot be converted into T. Hence, the answer is No.

For test case 3:

  • We can swap elements at indexes 1 and 3.
  • We can swap elements at indexes 4 and 2.
  • We can swap elements at indexes 0 and 2.
  • After the above operations, S can convert into T. Hence, the answer is Yes.
Editor Image

?