Check if One String Swap Can Make Strings Equal
Problem statement
Given two strings first and second of equal length, return true if they are already equal or can be made equal by swapping exactly two positions in first. Otherwise return false.
Function
areAlmostEqual(first: String, second: String) → booleanExamples
Example 1
first = "bank"second = "kanb"return = trueSwapping indices 0 and 3 in first produces second.
Example 2
first = "attack"second = "defend"return = falseMore than two positions differ.
Constraints
1 <= first.length == second.length <= 10^5.- Both strings contain lowercase English letters.