Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Negative Indexes solution in Clear category for Common Tail by dig
def common_tail(a: list[int], b: list[int]) -> int | None:
i = min(len(a), len(b))
if not a or not b: return None
while True:
if a[-i:] == b[-i:]:
return a[-i]
i -= 1
if i==0: return None
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!")
April 17, 2023
Comments: