Inspired by this
Your task today: given two strings, find the string with the lowest maximum Levenshtein distance to the input strings. For example, using Steffan
and Seggan
, the average string will be Steggan
. It is distance 2 from Steffan
(replace the gg
with ff
), and 1 from Seggan
(add a t
). That gives it a maximum distance of 2.
Other constraints:
- If there are multiple possibilities, output any of them or all of them (duplicates are OK)
- The inputs are distinct
- The input will be given in uppercase or lowercase ASCII, you choose
- There will always be common letters in the inputs
- The outputs will only have letters from the inputs
- There will always be a solution satisfying the above constraints
As this is code-golf, shortest code in bytes wins.
Testcases
seggan, steffan -> ['seffan', 'sefgan', 'segfan', 'stefgan', 'stegfan', 'steggan'] (2)
hello, ho -> ['hllo', 'hlo', 'helo', 'heo'] (2)
string, ring -> ['tring', 'sring'] (1),
aaa, aaaa -> ['aaa', 'aaaa'] (1)
abc, abcd -> ['abc', 'abcd', 'abd', 'abca', 'abcb', 'abcc'] (1)
abc, abcd
also beabd
? \$\endgroup\$hello, ho
is["heo", "hlo", "hel", "elo", "heol", "helo", "hleo", "ehlo", "elho", "hll", "llo", "holl", "hllo"]
. All of those have a max distance of 2 betweenhello, ho
. \$\endgroup\$