package leetcode;

/**
 * https://leetcode.com/problems/card-flipping-game/
 */
public class Problem822 {
    public int flipgame(int[] fronts, int[] backs) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem822 prob = new Problem822();
        System.out.println(prob.flipgame(new int[]{1, 2, 4, 4, 7}, new int[]{1, 3, 4, 1, 3})); // 2
        System.out.println(prob.flipgame(new int[]{2}, new int[]{3})); // 2
        System.out.println(prob.flipgame(new int[]{3}, new int[]{2})); // 2
    }
}

@@ -164,32 +164,734 @@
     
-// TODO%0A        return 0
+int%5B%5D set = new int%5B2000%5D;%0A        int result = Integer.MAX_VALUE;%0A        for (int i = 0; i %3C fronts.length; i++) %7B%0A            set%5Bfronts%5Bi%5D%5D++;%0A        %7D%0A        for (int i = 0; i %3C fronts.length; i++) %7B%0A            if (fronts%5Bi%5D == backs%5Bi%5D) %7B%0A                continue;%0A            %7D%0A            if (set%5Bfronts%5Bi%5D%5D == 1) %7B%0A                result = Math.min(result, fronts%5Bi%5D);%0A            %7D%0A            // Flip%0A            set%5Bbacks%5Bi%5D%5D++;%0A            set%5Bfronts%5Bi%5D%5D--;%0A            if (set%5Bbacks%5Bi%5D%5D == 1) %7B%0A                result = Math.min(result, backs%5Bi%5D);%0A            %7D%0A            // Restore%0A            set%5Bbacks%5Bi%5D%5D--;%0A            set%5Bfronts%5Bi%5D%5D++;%0A        %7D%0A        return result == Integer.MAX_VALUE ? 0 : result
 ;%0A  
@@ -1232,20 +1232,260 @@
 %7B2%7D)); // 2%0A
+        System.out.println(prob.flipgame(new int%5B%5D%7B3%7D, new int%5B%5D%7B3%7D)); // 0%0A        System.out.println(prob.flipgame(new int%5B%5D%7B1, 1%7D, new int%5B%5D%7B1, 2%7D)); // 2%0A        System.out.println(prob.flipgame(new int%5B%5D%7B1, 1%7D, new int%5B%5D%7B2, 2%7D)); // 1%0A
     %7D%0A%7D%0A

Update problem 822