C++ Solution || Clean and Simple || Easy to Understand
Problem\n\nGiven 2 faces of domino in to arrays tops and bottoms and return minimum number of flips after which either top or bottom have same elements in it. I
**Problem**\n\nGiven 2 faces of domino in to arrays tops and bottoms and return **minimum number of flips** after which **either top or bottom** have same elements in it. It this cannot be possible **return -1**\n\n**Approach**\n\nWe will return -1 whenever top and bottom are not equal to face value.(value which we are fliping for)\n\nElse we will just count flips for both top and bottom and return the min of both.\n\nGo through comments for better understanding\n\n**Code**\n```\nclass Solution {\npublic:\n    \n    int numberofflip(vector<int> &t,vector<int> &b, int num)\n    {\n        int cnt1=0,cnt2=0; // count for top and bottom flips\n        for(int i=0;i<t.size();++i)\n        {\n            if(t[i]!=num && b[i]!=num) // for face to be same num must be equal to either top or bottom\n                return -1; // if not return -1\n            \n            if(t[i]!=num)cnt1++; // top flips \n            if(b[i]!=num)cnt2++; // bot flips\n        }\n        \n        return min(cnt1,cnt2); // return minimum\n    }\n    \n    int minDominoRotations(vector<int>& tops, vector<int>& bottoms)\n    {\n        int top = numberofflip(tops,bottoms,tops[0]); // lets try with first num of top\n        int bot = numberofflip(tops,bottoms,bottoms[0]); // lets try with first num of bot\n        \n        // if min is positive return min of top and bot\n        // if min is negative(-1) return max of top and bot\n        return min(top,bot)>0?min(top,bot):max(top,bot);   \n    }\n};\n```\n\n**Upvote this post if it helps you\nLemme know if I missed something\nSee u in another post, untill then TATAKAE :)**
['Array', 'C']