#K44987. One Swap to Equal Strings
One Swap to Equal Strings
One Swap to Equal Strings
You are given two strings s and t of length \( n \). You are allowed to perform at most one swap operation on string s. Your task is to determine if it is possible to make s equal to t by performing at most one swap on s.
A swap operation consists of choosing two indices \( i \) and \( j \) (\( i \neq j \)) and exchanging the characters at those positions in s.
If s is already equal to t, you should return YES. Otherwise, if there are exactly two positions where s and t differ and swapping the mismatched characters in s makes it equal to t, output YES. In all other cases, output NO.
Note: All indices are 0-based and the strings consist of lowercase letters.
inputFormat
The input is given via standard input 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 a single line containing YES if it is possible to make string s equal to string t by performing at most one swap, otherwise output NO.
## sample5
abcde
abcde
YES