[JAVA] Clean Code, Count Array Technique, O(N) Time Complexity
\nclass Solution {\n\t\n\tpublic int minDominoRotations (int[] A, int[] B) {\n\t\n\t\tint[] countA = new int[7];\n\t\tint[] countB = new int[7];\n\t\tint[] coun
```\nclass Solution {\n\t\n\tpublic int minDominoRotations (int[] A, int[] B) {\n\t\n\t\tint[] countA = new int[7];\n\t\tint[] countB = new int[7];\n\t\tint[] countSame = new int[7];\n\t\t\n\t\tfor (int i = 0; i < A.length; i++) {\n\t\t\t++countA[A[i]];\n\t\t\t++countB[B[i]];\n\t\t\tif (A[i] == B[i]) {\n\t\t\t\t++countSame[A[i]];\n\t\t\t}\n\t\t}\n\t\t\n\t\tint ans =  A.length;\n\t\t\n\t\tfor (int i = 1; i <= 6; i++) {\n\t\t\tif (countA[i] + countB[i] - countSame[i] == A.length) {\n\t\t\t\tint min = Math.min (countA[i], countB[i]) - countSame[i];\n\t\t\t\tans = Math.min (ans, min);\n\t\t\t}\n\t\t}\n\t\t\n\t\treturn ans == A.length ? -1 : ans;\n\t}\n}\n```\n\nPlease help to **UPVOTE** if this post is useful for you.\nIf you have any questions, feel free to comment below.\n**HAPPY CODING :)\nLOVE CODING :)**\n
[]