Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for String Conversion by Elena_Korljukova
def steps_to_convert(line1, line2):
q = set(line1)&set(line2)
if len(q) == 0:
return max(len(line1), len(line2))
c1 = sorted([i for i in q], key = lambda x: line1.index(x))
c2 = sorted([i for i in q], key = lambda x: line2.index(x))
a = [c1[i] for i in range(len(c1) - 1) if c1[i + 1] in c2[c2.index(c1[i]) + 1:]]
a = (a + [c1[-1]] if c1[-1] in c2[c2.index(a[-1]) + 1 :] else []) if a else sorted(c1, key = lambda x: -len(x))[0]
return max(len(line1), len(line2)) - sum(len(i) for i in a)
if __name__ == "__main__":
#These "asserts" using only for self-checking and not necessary for auto-testing
assert steps_to_convert('line1', 'line1') == 0, "eq"
assert steps_to_convert('line1', 'line2') == 1, "2"
assert steps_to_convert('line', 'line2') == 1, "none to 2"
assert steps_to_convert('ine', 'line2') == 2, "need two more"
assert steps_to_convert('', '') == 0, "two empty"
assert steps_to_convert('l', '') == 1, "one side"
assert steps_to_convert('', 'l') == 1, "another side"
print("You are good to go!")
Sept. 18, 2020