Maximum non-crossing lines

Write codeMedium25 min

Your task

You are given two integer arrays a and b written on two horizontal lines. You may draw connecting lines between a[i] and b[j] only when a[i] == b[j], and no two connecting lines may cross (and each number is used at most once). Return the maximum number of connecting lines you can draw. Each array has at most 500 elements with values 1..2000.

Examples

max_uncrossed_lines(a: list[int], b: list[int]) -> int
Example 1
Inputmax_uncrossed_lines([1, 4, 2], [1, 2, 4])
Output2