C++ Solution || Hashmaps || O(n) time
\nclass Solution {\npublic:\n    int minDominoRotations(vector<int>& tops, vector<int>& bottoms) {\n        map<int,int> m1;\n        map<int,int> m2;\n        
```\nclass Solution {\npublic:\n    int minDominoRotations(vector<int>& tops, vector<int>& bottoms) {\n        map<int,int> m1;\n        map<int,int> m2;\n        map<int,int> m3;\n        map<int,int> m4;\n        \n        for(int i=0;i<tops.size();i++){\n            m1[tops[i]]++; \n            if(tops[i]!=bottoms[i]){\n                m4[tops[i]]++;\n            }\n        }\n        \n        for(int i=0;i<bottoms.size();i++){\n            if(bottoms[i]!=tops[i]){\n                m2[bottoms[i]]++;\n            }\n            m3[bottoms[i]]++;\n        }\n        \n        int res = INT_MAX;\n        int n = tops.size();\n        int m = bottoms.size();\n        \n        for(auto i:m1){\n            int num = i.first;\n            int freq = i.second;\n            \n            int req =  n - freq;\n            \n            if(m2[num]>=req){\n                res = min(res,req);\n            }\n        }\n        \n        \n        for(auto i:m3){\n            int num = i.first;\n            int freq = i.second;\n            \n            int req = m - freq;\n            \n            if(m4[num]>=req){\n                res = min(res,req);\n            }\n            \n            \n        }\n        \n        \n        if(res==INT_MAX){\n            return -1;\n        }\n        return res;\n        \n        \n        \n    }\n};\n```
[]