O(N) solution || each line explained || upvote if you like it
\nclass Solution {\npublic:\n    int minDominoRotations(vector<int>& T, vector<int>& B) {\n        // atfirst I\'ll try to make all the dices equal to top aka T
```\nclass Solution {\npublic:\n    int minDominoRotations(vector<int>& T, vector<int>& B) {\n        // atfirst I\'ll try to make all the dices equal to top aka T\n        for(int i=0,t=0,b=0;i<T.size() and (T[i]==T[0] or B[i]==T[0]);++i){\n            // where t and b denotes no. of swaps required\n            if(T[i]!=T[0]) ++t;\n            if(B[i]!=T[0]) ++b;\n            // return the minimum swap\n            if(i==T.size()-1)\n                return min(t,b);\n        }\n        // atfirst I\'ll try to make all the dices equal to bottom aka B\n        for(int i=0,t=0,b=0;i<T.size() and (T[i]==B[0] or B[i]==B[0]);++i){\n            // where t and b denotes no. of swaps required\n            if(T[i]!=B[0]) ++t;\n            if(B[i]!=B[0]) ++b;\n            if(i==T.size()-1)\n                // return the minimum swap\n                return min(t,b);\n        }\n        // nothing matches I\'ll simply return -1 \n        return -1;\n        \n    }\n};\n```
['C', 'C++']