C++ || Greedy Approach || TC:- O(N) || SC:- O(N) || Using two unordered_map
I know my solution is a lill bit of dumb it can be optimize further. But still if you like my solution please UPVOTE. It will motivate me a lot. Thank You!\n```
I know my solution is a lill bit of dumb it can be optimize further. But still if you like my solution please UPVOTE. It will motivate me a lot. Thank You!\n```\nint minDominoRotations(vector<int>& tops, vector<int>& bottoms) {\n        unordered_map<int, int> mpTop;\n        unordered_map<int, int> mpBot;\n        int maxTop=0, maxTopEle=0;\n        int maxBot=0, maxBotEle=0;\n        for(auto itr: tops){\n            mpTop[itr]++;\n        }\n        for(auto itr: bottoms){\n            mpBot[itr]++;\n        }\n        for(auto itr: mpTop){\n            if(maxTop<itr.second){\n                maxTop=max(maxTop, itr.second);\n                maxTopEle=itr.first;\n            }\n        }\n        for(auto itr: mpBot){\n            if(maxBot<itr.second){\n                maxBot=max(maxBot, itr.second);\n                maxBotEle=itr.first;\n            }\n        }\n        int cnt=0;\n        if(maxTop>maxBot){\n            for(int i=0;i<tops.size();i++){\n                if(maxTopEle==bottoms[i] and tops[i]!=bottoms[i]){\n                    cnt++;\n                }\n                else if(maxTopEle!=bottoms[i] and maxTopEle!=tops[i]){\n                    return -1;\n                }\n            }\n        }\n        else{\n            for(int i=0;i<tops.size();i++){\n                if(maxBotEle==tops[i] and tops[i]!=bottoms[i]){\n                    cnt++;\n                }\n                else if(maxBotEle!=tops[i] and maxBotEle!=bottoms[i]){\n                    return -1;\n                }\n            }\n        }\n        return cnt;\n    }
['C', 'C++']