Thought Process || JAVA O(N)
Thinking Process\nWe have to convert all dominos by swap to corrosponding array so that in anyone of the array all value became same.\n eg : A = [2,1,2,4,2,2], 
**Thinking Process**\nWe have to convert all dominos by swap to corrosponding array so that in anyone of the array all value became same.\n eg : A = [2,1,2,4,2,2], B = [5,2,6,2,3,2]\n So 4 Possiblities are there either we can convert all A to 2 or either 5. similarly we can convert all B to 2 or 5.\nwhichever is causing us **minimum cost** will go for that. Hope idea is clear to you\n\n\n```\n public int minDominoRotations(int[] A, int[] B) {\n        \n        int A2=0;\n        int A5=0;\n        \n        int B2=0;\n        int B5=0;\n         \n        int ans=0;\n        \n       for(int i=0;i<A.length;i++){\n           \n           if(A2!=Integer.MAX_VALUE){\n           if(A[i]!=A[0]){\n               if(B[i]==A[0]){\n                   A2+=1;\n               }else{\n                   A2=Integer.MAX_VALUE;\n               }\n           }\n           }\n           \n          if(A5!=Integer.MAX_VALUE){\n           if(A[i]!=B[0]){\n               if(B[i]==B[0]){\n                   A5+=1;\n               }else{\n                   A5=Integer.MAX_VALUE;\n               }\n           }\n          }\n           \n           if(B5!=Integer.MAX_VALUE){\n           if(B[i]!=B[0]){\n               if(A[i]==B[0]){\n                   B5+=1;\n               }else{\n                   B5=Integer.MAX_VALUE;\n               }\n           }\n           }\n           \n           if(B2!=Integer.MAX_VALUE){\n           if(B[i]!=A[0]){\n               if(A[i]==A[0]){\n                   B2+=1;\n               }else{\n                   B2=Integer.MAX_VALUE;\n               }\n           }\n           }     \n       }\n        \n        int tans1=Math.min(A2,A5);\n        int tans2=Math.min(B2,B5);\n        ans=Math.min(tans1,tans2);\n        if(ans==Integer.MAX_VALUE ) return -1;\n        return ans;\n    }\n```\t\n**Time : O(n) and Space:O(1)**\nPlease **UPVOTE** if founf it helpful:)
['Java']