An airport's tag printer stamps a code onto every checked bag. During one recorded malfunction, the printer swapped the characters sitting at exactly two positions of the code it stamped for a particular bag (it may also be that the two swapped positions happened to already hold identical characters, in which case the printed code looks unchanged). You are given the code that was actually printed, A, and the code the bag should have carried, B. Decide whether there is some pair of two distinct positions in A such that swapping the characters at those two positions turns A into exactly B.
Line 1: string A Line 2: string B Both strings consist only of lowercase English letters (a-z).
Print the single word "true" if some swap of two distinct positions in A produces exactly B, and "false" otherwise.
1 <= length of A, length of B <= 2000
Example 1
Input
ab ba
Expected
true
Explanation
Swapping the two positions of A = "ab" (position 0 and position 1) gives "ba", which equals B. So the answer is true.
Example 2
Input
ab ab
Expected
false
Explanation
A already equals B, but A's two characters ('a' and 'b') are both distinct, so there is no pair of equal characters to swap without actually changing the string. Since any real swap of A's two positions would turn it into "ba", not "ab", the answer is false.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →