Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
takewhile solution in Clear category for Common Tail by juestr
from itertools import takewhile
def common_tail(a: list[int], b: list[int]) -> int | None:
pairs_r = zip(reversed(a), reversed(b))
tail_r = [x for x, _ in takewhile(lambda p: p[0] == p[1], pairs_r)]
return (tail_r and tail_r[-1]) or None
Sept. 9, 2022