Given two strings S and T, determine if they are both one edit distance apart.
Hint:
-
If | n – m | is greater than 1, we know immediately both are not one-edit distance apart.
-
It might help if you consider these cases separately, m == n and m ≠ n.
-
Assume that m is always ≤ n, which greatly simplifies the conditional statements. If m > n, we could just simply swap S and T.
-
If m == n, it becomes finding if there is exactly one modified operation. If m ≠ n, you do not have to consider the delete operation. Just consider the insert operation in T.
Two pointers sliding