O(n) Solution CPP
\nclass Solution {\npublic:\n    vector<int> threeEqualParts(vector<int>& arr) {\n        vector<int> ans{-1,-1};\n        int count=0,ones=0,p1=0,p2=0,p3=0;\n 
```\nclass Solution {\npublic:\n    vector<int> threeEqualParts(vector<int>& arr) {\n        vector<int> ans{-1,-1};\n        int count=0,ones=0,p1=0,p2=0,p3=0;\n        for(int i=0; i<arr.size();i++){\n            count+=arr[i];\n        }\n        if(count%3) return ans;\n        if(count==0){\n            ans[0] = 0;\n            ans[1] = arr.size()-1;\n            return ans;\n        }\n        count/=3;\n        for(int i=0; i<arr.size(); i++){\n            if(arr[i]==1){\n                if(ones==0) p1 = i;\n                else if(ones==count) p2 = i;\n                else if(ones==2*count) p3 = i;\n                ones++;\n            }\n        }\n        int op2=p2,op3=p3;\n        while(p1<op2 && p2<op3 && p3<arr.size()){\n            if(arr[p1]!= arr[p2] || arr[p2]!=arr[p3]) return ans;\n            p1++; p2++; p3++;\n        }\n        if(p3!=arr.size()) return ans;\n        \n        ans[0] = p1-1;\n        ans[1] = p2;\n        return ans;\n    }\n};\n```\nInspired from :- https://leetcode.com/problems/three-equal-parts/discuss/1343568/C%2B%2B-O(n)-time-and-O(1)-space
[]