Detailed Explanation
Intuition\n Create a helper function minSteps that takes as input 2 vectors and a candidate and returns the minimum steps to convert every element in the target
**Intuition**\n* Create a helper function `minSteps` that takes as input 2 vectors and a `candidate` and returns the minimum steps to convert every element in the `target` array to `candidate`. It returns -1 if the target vector cannot be converted in the desired fashion. This function is used to remove code redundancy.\n* Create a frquency array and update the frequency of each element (as every element is in the range `[1,6]`.)\n* Traverse the frequency array and capture the `candidates`, i.e, elements which occur atleast half the time [inclusive]. Note that this is not the same as majority element as majority element should occur strictly more than `n/2` times(and hence Moore\'s Algorithm won\'t work). However, there can be atmost 2 candidates.\n* If there is no candidate, return -1\n* For each of the candidate, try to adjust it in both the top and bottom half and take the best outcome of the two.\n```\nclass Solution\n{\npublic:\n    int minDominoRotations(vector<int>& a, vector<int>& b);\n    int minSteps(vector<int>& source, vector<int>& target, int candidate);\n};\n\n/* Returns the min steps to convert every element in target to candidate */\nint Solution :: minSteps(vector<int>& source, vector<int>& target, int candidate)\n{\n    int swap = 0;\n    for(int i=0; i<source.size(); i++)\n    {\n        /*  If candidate is already in place, do nothing\n         *  If the candidate is present in the source, swap it\n         *  If the candidate is not present in either of them, it cannot be done\n         */\n        if(target[i]==candidate) continue;\n        else if(source[i]==candidate) swap++;\n        else return -1;\n    }\n    \n    return swap;\n}\n\n/* Returns the min steps to equalize each element in any vector */\nint Solution :: minDominoRotations(vector<int>& a, vector<int>& b)\n{\n    // Get the size, Create the frequncy and candidate vector\n    int n = a.size();\n    vector<int> freq(7,0);\n    vector<int> candidate;\n    \n    // Fill the frequency vector\n    for(int i=0; i<n; i++)\n        freq[a[i]]++, freq[b[i]]++;\n    \n    // Fill the candidate vectpr\n    for(int i=1; i<=6; i++)\n        if(freq[i]>=n) \n            candidate.push_back(i);\n    \n    // If there is no candidate, it cannot be done\n    if(candidate.size()==0) return -1;\n    \n    // Variable to store the min steps\n    int minCount = INT_MAX;\n    \n    // Try all the candidate elements (atmost 2)\n    for(int i=0; i<candidate.size(); i++)\n    {\n        // Try to fill the candidate in the top and bottom\n        int top = minSteps(b,a,candidate[i]);\n        int bot = minSteps(a,b,candidate[i]);\n        \n        // Update the best outcome\n        minCount  = min({minCount, top, bot});\n    }\n    \n    return minCount;\n}\n```
[]