Input
A string S of length between 2 and 30. The only letters in the string will be a
or b
.
Output
All strings within Levenshtein distance 2 of S. You must output all the strings without duplicates but in any order you like.
Example
If S = aaa
then the output would be (in any order):
aa
abab
ab
aabba
aaaa
abaa
bbaaa
aba
bbaa
babaa
bba
abaaa
abaab
baaa
baab
baaaa
baba
aabaa
ba
abba
aaba
aabb
abbaa
abb
aabab
aaaaa
aaaab
baaba
a
aaaba
aaabb
aaa
aab
ababa
aaab
bab
baa
baaab
Constraints
Your code must be fast enough that it would run to completion on TIO when S is of length 30. This is only to stop brute force solutions.
a
andb
? \$\endgroup\$abba
is missing from your example output, and so arebaba
,abaab
,aabab
andababa
. \$\endgroup\$