i shows tops[i] on top and has bottoms[i] underneath. You may flip any cards you like, possibly none.
After flipping, call a number *hidden* if it is underneath at least one card and visible on top of none. Return the smallest number that can be made hidden. If nothing can be hidden, return 0.tops=[3, 5, 2, 6], bottoms=[3, 1, 7, 2] → 1
1 is on the underside of the second card and nowhere else, so it is already hidden and not visible on top. Nothing can be smaller than 1.
tops=[4, 4, 9], bottoms=[4, 8, 6] → 6
4 is on both sides of the first card, so it is always visible. 6 is under the third card and no card shows 6 on top, so 6 is hidden. Neither 4 nor anything smaller works, so the answer is 6.
tops=[2], bottoms=[2] → 0
The only card has 2 on both sides, nothing can be hidden, so the answer is 0.
tops=[3, 5, 2, 6], bottoms=[3, 1, 7, 2]
1
Run checks the first 3 tests in your browser. Submit checks all 110 tests on the server, hidden ones included.