Simple Greedy Method, O(N)
Main Idea is that after rotations, the final arrangement should either have all values equal to tops[0] or bottoms[0].  Check if rotations can be done  for tops
Main Idea is that after rotations, the final arrangement should ***either have all values equal to tops[0] or bottoms[0].***  Check if rotations can be done  for tops[0] and return -1 if tops[0] value is not present for any *i*.\nSimilarly, count minimum  rotations for bottoms[0].\n\n```\nclass Solution {\npublic:\n    int check(int x, vector<int>& tops, vector<int>& bottoms, int n) {\n    int rA = 0, rB= 0;\n    for (int i = 0; i < n; i++) {\n      // rotations cannot be done\n      if (tops[i] != x && bottoms[i] != x) return -1;\n      // tops[i] != x and bottoms[i] == x\n      else if (tops[i] != x) rA++;\n      // tops[i] == x and bottoms[i] != x    \n      else if (bottoms[i] != x) rB++;\n    }\n    // min number of rotations to have all\n    // elements equal to x in either tops or bottoms\n    return min(rA, rB);\n  }\n\n  int minDominoRotations(vector<int>& tops, vector<int>& bottoms) {\n    int n = tops.size();\n    int rotations = check(tops[0], tops, bottoms, n);\n    // If one could make all elements in tops or bottoms equal to tops[0]\n    if (rotations != -1 || tops[0] == bottoms[0]) return rotations;\n    // If one could make all elements in tops or bottoms equal to bottoms[0]\n    else return check(bottoms[0], tops, bottoms, n);\n  }\n};\n```
[]