Well explained with comments.
Intuition\n Describe your first thoughts on how to solve this problem. \n- We basically have to check whether their exists an element in the arrays which has a 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- We basically have to check whether their exists an element in the arrays which has a total frequency of `n` (where `n` is the size of either of the arrays).\n- If there does not, we can `return -1` as it is not possible to make all tops equal or all bottoms equal.\n- If there does exist such a number, we wish to first replace all tops with that number and then all bottoms, and return the one which takes the minimum number of swaps.\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Create a map (say `mpp`) to store frequencies of the integers from both the arrays.\n- Iterate the arrays and do the following:\n```\nif(tops[i]==bottoms[i]) mpp[tops[i]]++;\n        else{\n            mpp[tops[i]]++;\n            mpp[bottoms[i]]++;\n        }\n}\n```\n- Traverse the map to check for the element having `freq==n` say `el`.\n- If no such element exists `return -1`.\n- Else:\n    - Traverse the `tops` and count the number of elements not equal to `el`.\n    - Traverse the `bottoms` and count the number of elements not equal to `el`.\n    - Return the minimum of the above to quantities.\n\n# Complexity\n- Time complexity:$$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int minDominoRotations(vector<int>& tops, vector<int>& bottoms) {\n        //1.) Find the integer which has a frequency of n or more in both the arrays combined.\n        map<int, int> mpp;\n        for(int i=0; i<tops.size(); i++){\n            if(tops[i]==bottoms[i]) mpp[tops[i]]++;\n            else{\n                mpp[tops[i]]++;\n                mpp[bottoms[i]]++;\n            }\n        }\n        int el;\n        bool flag = false;\n        for(auto it: mpp){\n            if(it.second==tops.size()){\n                el = it.first;\n                flag = true;\n                break;\n            } \n        }\n        // not possible to make \n        if(!flag) return -1;\n        int ans1 = 0, ans2 = 0;\n        // flip all to the top.\n        for(int i=0; i<tops.size(); i++){\n            if(tops[i]!=el) ans1++;\n        }\n\n        // flip all to the bottom.\n        for(int i=0; i<tops.size(); i++){\n            if(bottoms[i]!=el) ans2++;\n        }\n\n        return min(ans1, ans2);\n    }\n};\n```
['Greedy', 'C++']