Python || Very Easy Explanation || O(n) complexity || 90% faster
PLEASE UPVOTE IF YOU LIKE THE ANSWER\nIf there is a possible solution then the common number in all the dominoes should be either top or bottom of the first dom
**PLEASE UPVOTE IF YOU LIKE THE ANSWER**\nIf there is a possible solution then the common number in all the dominoes should be either top or bottom of the first domino.\nNow, either of them should keep repeating in further dominoes, else we will stop checking that possible solution (top or bottom of first domino).\nIf for any domino both sides are not common with the first domino we will return -1.\nNow, if the iteration completes over the list, we will find the minimum swaps. We know if the top or bottom of the first domino is the solution.\nEg, top = [1,2,1,1,2] bottom = [2,1,2,1,1]\n1. We should either swap all the dominoes which are not equal to the solution.\n\tEg, 1 is the solution, to make all top equal to 1, swap the tops which are 2, so 2 swaps needed.\n2. Or we should swap all the dominoes which are the solution, but while doing so we need to subtract the number of dominoes which have same top and bottom.\n\teg, swap all 1 on the top to make all the bottom 1s, but we should not swap index 3 as bottom index 3 is already 1, so total top 1 = 3, already bottom 1  = 1, total swaps = 2\n\t\n\tANSWER = 2 swaps\n```\nclass Solution:\n    def minDominoRotations(self, tops: List[int], bottoms: List[int]) -> int:\n        common1 = tops[0]\n        common2 = bottoms[0]\n        length = len(tops)\n        i = 0\n        commonCount = 0\n        break1 = False\n        break2 = False\n        if(common1==common2):\n            commonCount = commonCount+1\n            break2 = True\n        for i in range(1,length):\n            if(not break1):\n                if (tops[i]==common1 or bottoms[i]==common1):\n                    if (tops[i]==common1 and bottoms[i]==common1):\n                        commonCount = commonCount + 1\n                        break2 = True\n                    continue\n                else:\n                    break1 = True\n            if(not break2):\n                if (tops[i]==common2 or bottoms[i]==common2):\n                    if (tops[i]==common2 and bottoms[i]==common2):\n                        commonCount = commonCount + 1\n                        break1 = True\n                    continue\n                else:\n                    break2 = True\n            if(break1 and break2):\n                break\n        if(i==length-1):\n            if(not break1 and not break2):\n                return min(min(tops.count(common1)-commonCount,length-tops.count(common1)),min(bottoms.count(common2)-commonCount,length-bottoms.count(common2)))\n            elif(not break1):\n                return min(tops.count(common1)-commonCount,length-tops.count(common1))\n            else:\n                return min(bottoms.count(common2)-commonCount,length-bottoms.count(common2))\n        else:\n            return -1\n```\n\n**Feel free to ask anything if not clear**
['Python']