#822
Card Flipping Game
specialist · 935 · lc medium +32 · verified · 50% accepted · 192 likes · top 38%
Description
You have n cards arranged in a row, each with a positive integer printed on its front (fronts[i]) and back (backs[i]). Initially every card shows its front face up. You may flip any subset of cards.
After flipping, an integer is considered good if it appears face-down on at least one card and does not appear face-up on any card.
Return the smallest good integer that can be achieved. If no good integer exists, return 0.
Example 1:
Input: fronts = [1,2,4,4,7], backs = [1,3,4,1,3]
Output: 2
Explanation:
If we flip the second card, the face up numbers are [1,3,4,4,7] and the face down are [1,2,4,1,3].
2 is the minimum good integer as it appears facing down but not facing up.
It can be shown that 2 is the minimum possible good integer obtainable after flipping some cards.
Example 2:
Input: fronts = [1], backs = [1]
Output: 0
Explanation:
There are no good integers no matter how we flip the cards, so we return 0.
Code
1
2
3