C++ Solution || Beginner Friendly
\nclass Solution {\npublic:\n    int solve(vector<int>& tops, vector<int>& bottoms, int num1, int num2){\n        int c1 = 0, c2 = 0, c3 = 0, c4 = 0, n = tops.s
```\nclass Solution {\npublic:\n    int solve(vector<int>& tops, vector<int>& bottoms, int num1, int num2){\n        int c1 = 0, c2 = 0, c3 = 0, c4 = 0, n = tops.size();\n        \n      //c1 -> number of swaps required to make tops vector as num1\n        for(int i = 0; i < n; i++){\n            if(tops[i] != num1){\n                if(bottoms[i] == num1) c1++;\n                else{\n                    c1 = INT_MAX;\n                    break;\n                }\n            }\n        }\n        //c2 -> number of swaps required to make bottoms vector as num1\n        for(int i = 0; i < n; i++){\n            if(bottoms[i] != num1){\n                if(tops[i] == num1) c2++;\n                else{\n                    c2 = INT_MAX;\n                    break;\n                }\n            }\n        }\n\t\t\n        //c3 -> number of swaps required to make tops vector as num2\n        for(int i = 0; i < n; i++){\n            if(tops[i] != num2){\n                if(bottoms[i] == num2) c3++;\n                else{\n                    c3 = INT_MAX;\n                    break;\n                }\n            }\n        }\n\t\t\n        //c4 -> number of swaps required to make bottoms vector as num2\n        for(int i = 0; i < n; i++){\n            if(bottoms[i] != num2){\n                if(tops[i] == num2) c4++;\n                else{\n                    c4 = INT_MAX;\n                    break;\n                }\n            }\n        }\n        //return the minimum of these 4 possibilites\n        int ans = min(min(c1, c2), min(c3, c4));\n        return ans == INT_MAX ? -1 : ans;\n        \n    }\n    int minDominoRotations(vector<int>& tops, vector<int>& bottoms) {\n        return solve(tops, bottoms, tops[0], bottoms[0]);\n    }\n};\n```
['C', 'C++']