Easy C++ solution || Greedy approach
\n\n# Code\n\nclass Solution {\npublic:\n    int minDominoRotations(vector<int>& tops, vector<int>& bottoms) {\n        int n = tops.size();\n        int i = 0,
\n\n# Code\n```\nclass Solution {\npublic:\n    int minDominoRotations(vector<int>& tops, vector<int>& bottoms) {\n        int n = tops.size();\n        int i = 0, cur = tops[0], count1 = 0, start1 = 1, counter1 = 0;\n        while(i < n && start1 < n){\n            if(tops[i] != cur){\n                counter1 = 0;\n                if(bottoms[i] == cur){\n                    count1++;\n                    i++;\n                    counter1++;\n                }\n                else{\n                    i = 0;\n                    cur = tops[start1++];\n                    count1 = 0;\n                }\n            }\n            else{\n                i++;\n                counter1++;\n            }\n        }\n        bool topPossible = false;\n        if(counter1 > 0){\n            topPossible = true;\n        }\n\n\n        i = 0; cur = bottoms[0];\n        int count2 = 0, start2 = 1, counter2 = 0;\n        while(i < n && start2 < n){\n            if(bottoms[i] != cur){\n                counter2 = 0;\n                if(tops[i] == cur){\n                    count2++;\n                    i++;\n                    counter2++;\n                }\n                else{\n                    i = 0;\n                    cur = bottoms[start2++];\n                    count2 = 0;\n                }\n            }\n            else{\n                i++;\n                counter2++;\n            }\n        }\n        bool bottomPossible = false;\n        if(counter2 > 0){\n            bottomPossible = true;\n        }\n\n\n        int ans;\n        if(topPossible && bottomPossible){\n            ans = min(count1, count2);\n            return ans;\n        }\n        if(topPossible){\n            return count1;\n        }\n        if(bottomPossible){\n            return count2;\n        }\n\n\n\n        return -1;\n    }\n};\n```
['Array', 'Greedy', 'C++']