✔ Problem Approach || Greedy Intution || C++
Intution\nThe problem statement says that we have to set all the values of either top or bottom array to be same\nNow , this can only be done if some number fro
## Intution\nThe problem statement says that we have to set all the values of either top or bottom array to be same\nNow , this can only be done if some number from 1 to 6 is present at every index in either of the 2 arrays.\n**Begining Approach**\nSince numbers are only from 1 to 6 , we can just loop over every number and just check if it satisfies the criteria \nthat it is present at each index in either or both of the 2 arrays.\nIf any number satisfies the criteria , in can be the answer and hence we calculate how many times it has occured \nin both the arrays and store them in seperate variables.\nAfter this is done , we can easily get our answer\nsince we have count of how many times number has occured in both the arrays , we find our answer as\nans = minimum( ans , sizeofarray - maximum occ of the number in both the arrays ) .\n\n**Follow up:**\nThere can be at max 2 numbers who can fulfill the criteria. Try to think why ? It should be easy as you have understood the problem \uD83D\uDE03\uD83D\uDE03\n\n```\nclass Solution {\npublic:\n    int minDominoRotations(vector<int>& tops, vector<int>& bottoms) {\n        \n        int ans = 1e6;\n\n        for(int dice=1 ; dice<=6 ; dice++)\n        {\n            bool flag = 0;\n            int topcnt = 0 , bottomcnt = 0 ;\n            \n            for(int i=0; i<tops.size() ; i++)\n            {\n                if(tops[i]!= dice && bottoms[i]!= dice)\n                    flag = 1 ;\n                \n                if(tops[i] == dice)\n                    topcnt++ ;\n                \n                if(bottoms[i] == dice)\n                    bottomcnt++;\n            }\n            \n            if(flag) continue ; \n            \n            ans = min( ans , int(tops.size()) - max(topcnt , bottomcnt) ) ;\n            \n        }\n        \n        if(ans == 1e6 ) ans = -1 ;\n        \n        return ans ;\n    }\n};
['Greedy', 'C']