Mid/SeniorArrayHash Table

Card Flipping Game

You are given two 0-indexed integer arrays fronts and backs of length n, where the i^th card has the positive integer fronts[i] printed on the front and backs[i] printed on the back. Initially, each card is placed on a table such that the front number is facing up and the other is facing down. You may flip over any number of cards, possibly zero.

After flipping the cards, an integer is considered good if it is facing down on some card and not facing up on any card.

Return the minimum possible good integer after flipping the cards. If there are no good integers, return 0.

Example 1
Inputfronts = [1,2,4,4,7], backs = [1,3,4,1,3]
Output2
If we flip the second card, 2 appears facing down but not facing up, and it is the minimum possible good integer obtainable.
Example 2
Inputfronts = [1], backs = [1]
Output0
There are no good integers no matter how we flip the cards, so we return 0.

Constraints

  • n == fronts.length == backs.length
  • 1 <= n <= 1000
  • 1 <= fronts[i], backs[i] <= 2000

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate