LeetCode 822, Medium. Topics: Array, Hash Table. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 19 parametrized pytest cases, and a playground notebook:
Problem
You are given two <strong>0-indexed</strong> integer arrays <code>fronts</code> and <code>backs</code> of length <code>n</code>, where the <code>i<sup>th</sup></code> card has the positive integer <code>fronts[i]</code> printed on the front and <code>backs[i]</code> 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 <strong>good</strong> if it is facing down on some card and <strong>not</strong> facing up on any card.
Return <em>the minimum possible good integer after flipping the cards</em>. If there are no good integers, return <code>0</code>.
Examples
Constraints
- n == fronts.length == backs.length
- 1 <= n <= 1000
- 1 <= fronts[i], backs[i] <= 2000
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Last modified on September 7, 2026