Java intuitive solution(Using just first elements of both arrays)
\nclass Solution {\n    public int minDominoRotations(int[] tops, int[] bottoms) {\n        //val1 is minimum swaps needed for all tops elements to be same and 
```\nclass Solution {\n    public int minDominoRotations(int[] tops, int[] bottoms) {\n        //val1 is minimum swaps needed for all tops elements to be same and val2 is minimum swaps needed for all \n\t\t//bottoms elements to be same. Since all elements should be same, either all elements should be equal to first \n\t\t//element of tops or first element of bottoms. So just calculating how many swaps will be needed for that a \n\t\t//swap function was called in 4 different cases.\n        int val1 = Math.min(swapsNeeded(tops,bottoms,tops[0]),swapsNeeded(tops,bottoms,bottoms[0]));\n        int val2 = Math.min(swapsNeeded(bottoms,tops,tops[0]),swapsNeeded(bottoms,tops,bottoms[0]));\n        int ans = Math.min(val1,val2);\n        if(ans==Integer.MAX_VALUE){\n            return -1;\n        }else{\n            return ans;\n        }\n    }\n    //calculating no of swaps needed for elements to be same.\n    public int swapsNeeded(int[] tops, int[] bottoms, int val){\n        int swaps = 0,i = 0;\n        for(;i<tops.length;i++){\n            if(tops[i]!=val&&bottoms[i]!=val){\n                return Integer.MAX_VALUE;\n            }else if(tops[i]!=val&&bottoms[i]==val){\n                swaps++;\n            }\n        }\n        return swaps;\n    }\n}\n```\nPlease upvote if it helped you. Thank you!
['Array', 'Java']