Java one pass solution with explanations
Here is my thinking process for this problem, first we need to get the frequency of number for each array, if number in A is equal to number in B at the same in
Here is my thinking process for this problem, first we need to get the frequency of number for each array, if number in A is equal to number in B at the same index, then the frequency for this number will be added once in the "same" array, which is used to store the frequency of number in A equal to number in B at the same index.\n\nAfter the three arrays have been obtained as above, the number from 1 to 6 will be iterated, only if the frequency of a specific number from 1 ~ 6 in A plus that in B minus the frequency that number appears in both array equal to the length of array will give us the result. otherwise, it needs to return as -1.    \n```\nclass Solution {\n    public int minDominoRotations(int[] A, int[] B) {\n        int[] numberOfA = new int[7];\n        int[] numberOfB = new int[7];\n        int[] same = new int[7];\n        for(int i = 0; i < A.length; i++) {\n            numberOfA[A[i]]++;\n            numberOfB[B[i]]++;\n            if(A[i] == B[i]) same[A[i]]++;\n        }\n        \n        for(int i = 1; i <= 6; i++) {\n            if(numberOfA[i] + numberOfB[i] - same[i] == A.length) {\n                return Math.min(numberOfA[i] - same[i], numberOfB[i] - same[i]);\n            }\n        }\n        return -1;\n    }\n}
[]