Java || Array + Greedy || 3ms || beats 98.43% || T.C - O(N) S.C - O(1)
\n    // O(A.length) O(1)\n\tpublic int minDominoRotations(int[] A, int[] B) {\n\n\t\tint len = A.length;\n\t\tint possible1 = A[0], possible2 = B[0];\n\t\tint 
\n    // O(A.length) O(1)\n\tpublic int minDominoRotations(int[] A, int[] B) {\n\n\t\tint len = A.length;\n\t\tint possible1 = A[0], possible2 = B[0];\n\t\tint max1 = minimumMoves(A, B, possible1, len);\n\t\tint max2 = minimumMoves(A, B, possible2, len);\n\t\tint max3 = minimumMoves(B, A, possible1, len);\n\t\tint max4 = minimumMoves(B, A, possible2, len);\n\t\tint max = Math.min(Math.min(max1, max2), Math.min(max3, max4));\n\t\treturn (max == Integer.MAX_VALUE) ? -1 : max;\n\t}\n\n\t// O(A.length) O(1)\n\tpublic int minimumMoves(int[] A, int[] B, int tile, int len) {\n\n\t\tint count = 0;\n\t\tfor (int i = 0; i < len; i++) {\n\t\t\tif (A[i] != tile && B[i] == tile)\n\t\t\t\tcount++;\n\t\t\telse if (A[i] != tile && B[i] != tile)\n\t\t\t\treturn Integer.MAX_VALUE;\n\t\t}\n\t\treturn count;\n\t}
[]