822. Card Flipping Game

Difficulty:
Related Topics:
Similar Questions:

    Problem

    You are given two 0-indexed integer arrays fronts and backs of length n, where the ith 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:

    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.
    

      Constraints:

    Solution (Java)

    class Solution {
        public int flipgame(int[] fronts, int[] backs) {
            int max = findMax(fronts, backs);
            int value = 10000;
            int[] twinCardHash = new int[max + 1];
            int[] existingNumbersHash = new int[max + 1];
            for (int i = 0; i < fronts.length; i++) {
                if (fronts[i] == backs[i]) {
                    twinCardHash[fronts[i]]++;
                }
                existingNumbersHash[fronts[i]]++;
                existingNumbersHash[backs[i]]++;
            }
            for (int i = 1; i <= max; i++) {
                if ((twinCardHash[i] == 0) && (i < value) && (existingNumbersHash[i] != 0)) {
                    value = i;
                    break;
                }
            }
            if (value == 10000) {
                return 0;
            } else {
                return value;
            }
        }
    
        private static int findMax(int[] fronts, int[] backs) {
            int max = 0;
            for (int front : fronts) {
                if (max < front) {
                    max = front;
                }
            }
            for (int back : backs) {
                if (max < back) {
                    max = back;
                }
            }
            return max;
        }
    }
    

    Explain:

    nope.

    Complexity: