Take as input two strings \$A\$ and \$B\$. Output a string \$C\$ that is \$A\$ but with two characters swapped such that the Levenshtein distance \$d(C,B)\$ is as small as possible. You must swap two characters and you cannot swap a character with itself, although you may swap two identical characters in different positions.
This is code-golf the goal is to minimize the size of your source code as measured in bytes.
Instead of strings you may instead choose to handle lists of positive integers.
Examples
Here are some examples of inputs and possible outputs along with the Levenshtein distance achieved.
A | B | C | Distance |
---|---|---|---|
abcd |
adcb |
adcb |
0 |
ybgh |
epmn |
ygbh |
4 |
slime |
slime |
silme |
2 |
yeboc |
yoqqa |
yobec |
3 |
unnua |
muuna |
uunna |
2 |
oobis |
oobi |
oobis |
1 |
yuace |
yuac |
yuaec |
1 |