easy c++ | O(n) | faster than 99.4% solution
class Solution {\npublic:\n    vector threeEqualParts(vector& arr) {\n        int i,j,x=0,n=arr.size();\n        for(i=0;iv(2);\n        if(x%3!=0){\n          
class Solution {\npublic:\n    vector<int> threeEqualParts(vector<int>& arr) {\n        int i,j,x=0,n=arr.size();\n        for(i=0;i<n;i++){\n            if(arr[i]==1) x++;\n        }\n        vector<int>v(2);\n        if(x%3!=0){\n            v[1]=v[0]=-1;\n            return v;\n        }\n        if(x==0){\n            v[0]=0;v[1]=n-1;\n            return v;\n        }\n        int k=0;\n        for(i=n-1;i>=0;i--){\n            if(arr[i]==1) break;\n            k++;\n        }\n        int z=0;\n        vector<int>a;\n        for(i=n-1;i>=0;i--){\n            if(arr[i]==1) z++;\n            a.push_back(arr[i]);\n            if(z==x/3){\n                v[1]=i;break;\n            }\n            \n        }\n        z=0;\n        for(i=v[1]-1;i>=0;i--){\n            if(arr[i]==1) break;\n            z++;\n        }\n        if(z<k){\n            v[1]=v[0]=-1;\n            return v;\n        }\n        z=i+k; v[1]=z+1;\n        int sz=a.size();\n        for(j=0;j<sz;j++){\n            if(arr[z]!=a[j]){\n                v[1]=v[0]=-1;\n                return v;\n            }\n            z--;\n        }\n        v[0]=z;\n        z=0;\n        for(i=v[0];i>=0;i--){\n            if(arr[i]==1) break;\n            z++;\n        }\n        if(z<k){\n            v[1]=v[0]=-1;\n            return v;\n        }\n        z=i+k; v[0]=z;\n        for(j=0;j<sz;j++){\n            if(arr[z]!=a[j]){\n                v[1]=v[0]=-1;\n                return v;\n            }\n            z--;\n        }\n        while(z>=0){\n            if(arr[z]==1){\n                v[1]=v[0]=-1;\n                return v;\n            }\n            z--;\n        }\n        return v;\n    }\n};
[]