C++ O(n) time O(1) space with comments.
If the number at each segment is same, the binary of those segment will also be same. \nThe key thing is to split all the ones into 3 equal parts. Then, the las
If the number at each segment is same, the binary of those segment will also be same. \nThe key thing is to split all the ones into 3 equal parts. Then, the last segment is final, it will be the value against which first 2 segments need to be compared.\n```\nvector<int> threeEqualParts(vector<int>& A) {\n        int cnt = 0, i, a, b, c, val = 0;\n        for (auto x : A)\n            cnt += x;\n        if (cnt == 0)\n            return {0, 2};\n        if (cnt % 3) // number of 1\'s are not splittable\n            return {-1,-1};\n        for (i = A.size() - 1; i >= 0; i--) {\n            if (A[i]) {\n                val++;\n                if (val == cnt/3)\n                    c = i; // start of 3rd segment\n                else if (val == 2 * (cnt/3))\n                    b = i; // start of 2nd segment\n                else if (val == cnt) {\n                    a = i; // start of 1st segment\n                    break;\n                }\n            }\n        }\n        for (i = 0; i < (int)A.size() - c; i++) {\n            if (a+i >= b || b+i >= c) // overlapping regions\n                return {-1, -1};\n            if (A[c+i] != A[a+i] || A[c+i] != A[b+i]) // mismatch\n                return {-1, -1};\n        }\n        return {a+i-1, b+i};\n    }\n\t```
[]