Question: Given two strings A and B of lowercase letters, return true if you can swap two letters in A so the result is equal to
Given two strings A and B of lowercase letters, return true if you can swap two letters in A so the result is equal to B, otherwise, return false. Sample test case 1: Input: A = "ab", B = "ba" Output: true Explanation: You can swap A[0] = 'a' and A[1] = 'b' to get "ba", which is equal to B. Sample test case 2: Input: A = "ab", B = "ab" Output: false Explanation: The only letters you can swap are A[0] = 'a' and A[1] = 'b', which results in "ba" != B. Sample test case 3: Input: A = "aa", B = "aa" Output: true Explanation: You can swap A[0] = 'a' and A[1] = 'a' to get "aa", which is equal to B. Sample test case 4: Input: A = "aaaaaaabc", B = "aaaaaaacb" Output: true Sample test case 5: Input: A = "", B = "aa" Output: false. And produce a read me file with all the documentation and the explanation of the code.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
