O(N) Python Solution
For each tile face (1-6), count the number of times the face appears on exactly BOTH sides of a domino, on ONLY the top side of a domino, and on ONLY the bottom
For each tile face (1-6), count the number of times the face appears on exactly BOTH sides of a domino, on ONLY the top side of a domino, and on ONLY the bottom side of a domino. For there to be a solution, the sum of these three values must be equal to the total number of dominos (because they are mutually exclusive sets). If a solution is found, return the MIN(ONLY_TOP_SIDE, ONLY_BOTTOM_SIDE), because we must flip one of these sets, so we should flip the minimum. Note that there could be two faces such that the sum of the three sets equals the number of dominos, but the number of flips will be the same.\n\n```\nclass Solution:\n    def minDominoRotations(self, A: List[int], B: List[int]) -> int:\n        domino_faces = 6\n        num_dominos = len(A)\n        domino_location_count = [[0, 0, 0] for _ in range(domino_faces+1)]\n        for i in range(num_dominos):\n            value_top = A[i]\n            value_bottom = B[i]\n            if value_top == value_bottom:\n                domino_location_count[value_top][0] += 1\n            else:\n                domino_location_count[value_top][1] += 1\n                domino_location_count[value_bottom][2] += 1\n        for value in range(domino_faces+1):\n            if sum(domino_location_count[value]) == num_dominos:\n                return min(domino_location_count[value][1], domino_location_count[value][2])\n        return -1\n```
[]