word and target. You must make exactly one swap: pick two *different* positions i and j in word and exchange the letters at them. The swap is required; you cannot skip it.
Return True if word can become equal to target after such a swap, and False otherwise.word="stop", target="spot" → True
Swap t (position 1) and p (position 3): stop → spot.
word="code", target="code" → False
The strings already match, but every letter is different, so any swap breaks the word. The answer is False.
word="level", target="level" → True
You can swap the two ls (or the two es) and the word stays the same. The answer is True.
word and target consist of lowercase English lettersword="stop", target="spot"
True
Run checks the first 3 tests in your browser. Submit checks all 129 tests on the server, hidden ones included.