top and the bottom row bottom, each in the given order. A top card can be tied to a bottom card with a string if both show the same number.
Strings are pulled straight and must not cross. Each card can hold at most one string, so even sharing an end counts as crossing.
Return the largest number of strings you can stretch.top=[7, 3, 9, 3], bottom=[3, 7, 3, 9] → 3
Strings 7–7, 3–3 (the second top card to the third bottom card) and 9–9 do not cross. A fourth one is impossible: the last top 3 sits right of the 9, while the free bottom 3 sits left of it.
top=[4, 4, 4], bottom=[4, 4] → 2
Only two pairs of 4s can be tied: there are just two cards at the bottom, and each card holds at most one string.
top=[1, 2], bottom=[3, 4] → 0
top=[7, 3, 9, 3], bottom=[3, 7, 3, 9]
3
Run checks the first 3 tests in your browser. Submit checks all 109 tests on the server, hidden ones included.