✅ C++ || Easy to Understand || Friendly O(n)  || 🗓️ Daily LeetCoding Challenge || March || Day 20
Please Upvote if it helps\u2B06\uFE0F\n\nAlgorithm\n we will keep three vectors\n\n one for counting the tops elements count\n one for counting the bottoms elem
Please Upvote if it helps\u2B06\uFE0F\n\n**Algorithm**\n* we will keep **three vectors**\n\n* one for counting the **tops elements count**\n* one for counting the **bottoms elements count**\n* one for counting the **same between tops and bottms** \n* after the calculations\n* we know that if there , whole equal row is possible then there is a element that will occour excatly **size of tops times**\n* So for that we will just kepp counting for all the possible numbers for **1 to 6**  \n* each time we will **add the frequeny of tops amd bottoms and subtract the same occurance count** \n* if it is equal to the our size then just return the **size-max(CountTop,CountBottom)** , it is our ans\n* Otherwise **return -1**\n\n\n```\nclass Solution {\npublic:\n    int minDominoRotations(vector<int>& tops, vector<int>& bottoms) \n    {\n        vector<int> CountTop(7);              // possibilities are 1 to 6 thats why {1,2,3,4,5,6}\n        vector<int> CountBottom(7);\n        vector<int> Same(7);\n        \n        int size = tops.size();               // extracting the size of tops\n        for(int i=0;i<size;i++)\n        {\n            CountTop[tops[i]]++;\n            \n            CountBottom[bottoms[i]]++;\n            \n            if(tops[i]==bottoms[i])\n                Same[tops[i]]++;\n        }\n        \n        // here we will be deriving our answer\n        for(int i=0;i<7;i++)\n        {\n            // we know that if there , whole equal row is possible then there is a element that will occour excatly size of tops times\n            // So for that we will just kepp counting for all the possible numbers for 1 to 6 \n            // each time we will add the frequeny of tops amd bottoms and subtract the same occurance count \n            // if it is equal to the our size then just return the n-max(CountTop,CountBottom) , it is our ans\n            if(CountTop[i] + CountBottom[i] - Same[i] == size)\n                return size-max(CountTop[i],CountBottom[i]);\n        }\n        \n        // if there is none such a element \n        return -1;\n    }\n};\n```\nPlease Upvote if it helps\u2B06\uFE0F
[]