- Two situations:
s === goal, only if there are duplicates in them.
s !== goal, find the unmatched chars and check if they match after one of them being reversed.
Given two strings
true if you can swap
two letters in
s so the result is equal to
goal, otherwise, return
Swapping letters is defined as taking two indices
j (0-indexed) such that
i != j and swapping the characters at
For example, swapping at indices
2 in “
abcd“ results in “
Input: s = "ab", goal = "ba"