Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Using zip() and index() solution in Clear category for Common Tail by H0r4c3
def common_tail(a: list[int], b: list[int]) -> int | None:
try:
if a[-1] != b[-1]:
return None
except:
return None
z = list(zip(a[::-1], b[::-1]))
for item in z:
if item[0] != item[1]:
idx = z.index(item)
return (z[idx-1])[0]
return a[0]
print("Example:")
print(common_tail([1, 2, 3, 4], [5, 6, 3, 4]))
# These "asserts" are used for self-checking
assert common_tail([], [1, 2, 3]) == None
assert common_tail([1], [1]) == 1
assert common_tail([3], [1, 2, 3]) == 3
print("The mission is done! Click 'Check Solution' to earn rewards!")
Dec. 23, 2022