Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second: No intermediate list, just find it on the fly solution in Clear category for Common Tail by ysenko
def lists_intersect(a: list[int], b: list[int]) -> int | None:
a_rev = reversed(a)
b_rev = reversed(b)
first_common_el = None
for el_a, el_b in zip(a_rev, b_rev):
if el_a != el_b:
break
first_common_el = el_a
return first_common_el
print("Example:")
print(lists_intersect([1, 2, 3, 4], [5, 6, 3, 4]))
assert lists_intersect([], [1, 2, 3]) == None
assert lists_intersect([1], [1]) == 1
assert lists_intersect([3], [1, 2, 3]) == 3
print("The mission is done! Click 'Check Solution' to earn rewards!")
Sept. 9, 2022
Comments: