[C++]O(n) time, simple sol with explaination
cpp\nclass Solution {\npublic:\n    vector<int> threeEqualParts(vector<int>& A) {\n        // check number of 1s\n        int oneCount = 0, n = A.size();\n     
```cpp\nclass Solution {\npublic:\n    vector<int> threeEqualParts(vector<int>& A) {\n        // check number of 1s\n        int oneCount = 0, n = A.size();\n        for (int &i: A)\n            oneCount += (i == 1);\n        if (oneCount % 3 != 0)\n            return vector<int> {-1, -1};\n        if (oneCount == 0)\n            return vector<int> {0, 2};\n        \n        // find last part\n        int count = oneCount / 3, third = n;\n        while (count > 0) {\n            third--;\n            if (A[third] == 1)\n                count--;\n        }\n        \n        // find first part\n        int first = 0;\n        while (first < n && A[first] == 0)\n            first++;\n        \n        // check equalness of 1 and 3\n        bool equal = true;\n        for (int offset = 0; third + offset < n; offset++)\n            if (first + offset >= third || A[first + offset] != A[third + offset])\n                return vector<int> {-1, -1};\n        \n        // check equalness of 2 and 3\n        int second = first + n - third;\n        while (A[second] == 0)\n            second++;\n        for (int offset = 0; third + offset < n; offset++)\n            if (second + offset >= third || A[second + offset] != A[third + offset])\n                return vector<int> {-1, -1};\n\n        // okay. return last position of first part and first position of third part.\n        return vector<int> {first + n - third - 1, second + n - third};\n    }\n};\n```
[]