Explaination with comments | CPP
```\nclass Solution {\npublic:\n    \n    // Idea is to count frequency of each number (1 to 6) in A and B.\n    int minDominoRotations(vector& A, vector& B) {\
```\nclass Solution {\npublic:\n    \n    // Idea is to count frequency of each number (1 to 6) in A and B.\n    int minDominoRotations(vector<int>& A, vector<int>& B) {\n        int n = A.size();\n        int hA[7] = {0};            //stores frequency of numbers in A.\n        int hB[7] = {0};            //stores frequency of numbers in B.\n        int same[7] = {0};          //stores frequency of numbers which are same in both at same position.\n        \n        //count frequency\n        for(int i=0; i<n; i++){\n            int t1 = A[i], t2 = B[i];\n            hA[t1]++;hB[t2]++;\n            if(t1==t2)same[t1]++;\n        }\n        \n        int res = n;\n        for(int i=1; i<=6; i++){\n            //checking is it possible to either A or B have this number at all positions.\n            if(hA[i]+hB[i]-same[i] == n){\n                res = min(res, min(hA[i], hB[i]) - same[i]);\n            }\n        }\n        return res == n ? -1:res;\n        //please appreciate\n    }\n};
['C', 'C++']