1007 | C++ | Easy O(N) solution with explanation
Please upvote if you find this solution helpful :)\nApproach:\n1. Define faceA for storing no. of occurences on tops\n2. Define faceB for storing no. of occuren
**Please upvote if you find this solution helpful :)**\n**Approach:**\n1. Define **faceA** for storing no. of occurences on tops\n2. Define **faceB** for storing no. of occurences on bottoms\n3. Define **same** for storing same no. of occurences on both dominoes.\n4. After covering all 6 possibilities if it satisfy this condition **(faceA[i] + faceB[i] - same[i] == size)**\n5. Then we calculate min rotation as **min_rotate = min(min_rotate, min(faceA[i], faceB[i]) - same[i])** where **min_rotate = INT_MAX**\n6. and if min_rotate!=INT_MAX return min_rotate else -1.\n\n**Time Complexity: O(N), Space Complexity: O(1).**\n\n**Code:**\n```\nclass Solution {\npublic:\n    int minDominoRotations(vector<int>& tops, vector<int>& bottoms) \n    {\n        int n=tops.size();\n        //define faceA for storing no. of occurences on tops\n        //define faceB for storing no. of occurences on bottoms\n        //define same for storing same no. of occurences on both dominoes\n        vector<int> faceA(7), faceB(7), same(7);\n        \n        //storing frequency of each no.\n        for(int i=0; i<n; i++)\n        {\n            faceA[tops[i]]++;\n            faceB[bottoms[i]]++;\n            \n            if(tops[i]==bottoms[i])\n                same[tops[i]]++;\n        }\n        \n        \n        int rotate = INT_MAX;\n        //over all 6 possibilities\n        for(int i=1; i<=6; i++)\n        {\n            if(faceA[i]+faceB[i]-same[i]==n)\n            {\n                rotate = min(rotate, min(faceA[i], faceB[i]) - same[i]);\n            }\n        }\n        \n        return rotate==INT_MAX ? -1 : rotate; \n        \n        \n    }\n};\n```\n\n**Please upvote if you find this solution helpful :)**
['C']