Ensure that you are logged in and have the required permissions to access the test.

Swapping positions

4.3

29 votes
Ad-Hoc, Algorithms, Basic Programming, Basics of Implementation, Easy, Implementation
Problem

You are given two strings s and t of length n. You can select any two positions (can be from the same or different strings) and swap the characters at those two positions. You have to perform this operation exactly once in such a way that there exists maximum one position i (1in) such that si!=ti
Determine whether it is possible to perform the operation such that the given condition holds or not.

Input format

  • First line: A single integer T that denotes the number of test cases 
  • For each test case:
    • First line: An integer n 
    • Next two lines: Strings s and t respectively

Output format

For each test case, print YES if a valid operation exists otherwise print NO in a single line.

Input constraints

  • 1T50
  • 1n103
  • Both the strings s and t contain only lowercase English alphabets
Sample Input
2
8
mrxismrx
mryismry
8
iamnomrx
iamdamry
Sample Output
YES
NO
Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

In the first test case, we can get a valid result by swapping the characters s3 and t8 (1 based indexing).

Contributers:
Editor Image

?