Solution
C++ []\nclass Solution {\npublic:\n    vector<int> threeEqualParts(vector<int>& arr) {\n     \n        int countone=count(arr.begin(),arr.end(),1);\n        int
```C++ []\nclass Solution {\npublic:\n    vector<int> threeEqualParts(vector<int>& arr) {\n     \n        int countone=count(arr.begin(),arr.end(),1);\n        int n=arr.size();\n        if(countone%3)\n        {\n            return {-1,-1};\n        }\n        if(countone==0)\n        {\n            return {0,n-1};\n        }\n        int total=countone/3;\n        int p1=0,p2=0,p3=0;\n        int count=0;\n        \n        for(int i=0;i<n;i++)\n        {\n            if(arr[i]==1)\n            {\n                if(count==0)\n                {\n                    p1=i;\n                }\n                else if(count==total)\n                {\n                    p2=i;\n                }\n                else if(count==2*total)\n                {\n                    p3=i;\n                }\n                count+=1;\n            }\n        }\n        while(p3<n-1)\n        {\n            p1+=1;\n            p2+=1;\n            p3+=1;\n            if(arr[p1]!=arr[p2] || arr[p2]!=arr[p3] || arr[p1]!=arr[p3])\n            {\n                return {-1,-1};\n            }\n        }\n        return {p1,p2+1};\n    } \n};\n```\n\n```Python3 []\nclass Solution:\n    def threeEqualParts(self, arr: List[int]) -> List[int]:\n        \n        ones = [i for i, j in enumerate(arr) if j==1]\n        n=len(ones)\n\n        if not ones:\n            return [0, 2]\n        if n%3:\n            return [-1, -1]\n        \n        i,j,k = ones[0], ones[n//3], ones[n//3*2]\n        l = len(arr)-k\n\n        if arr[i:i+l]==arr[j:j+l]==arr[k:k+l]:\n            return [i+l-1, j+l]\n\n        return [-1, -1]\n```\n\n```Java []\nclass Solution {\n    public int[] threeEqualParts(int[] arr) {\n        int oneSum = 0;\n        for(int x : arr) oneSum +=x;\n        if(oneSum % 3 !=0)return new int[]{-1,-1};\n        if(oneSum == 0)return new int[]{0,2};\n        int oneCount = oneSum / 3;\n        int i = 0;\n        int firstOne = -1;\n        int n= arr.length;\n        int lastZeroCount = 0;\n        i = n-1;\n        while(arr[i] ==0){\n            lastZeroCount++;\n            i--;\n        }\n        i=0;\n        while(oneCount > 0){\n            if(arr[i] == 1 && firstOne == -1)firstOne = i;\n            oneCount-=arr[i++];\n        }\n        while(lastZeroCount > 0){\n            if(arr[i++] == 1)return new int[]{-1,-1};\n            lastZeroCount--;\n        }\n        int k = i--;\n        int t = firstOne;\n        while(arr[k] == 0)k++;\n        while(firstOne <=i){\n            if(arr[firstOne++] != arr[k++])return new int[]{-1,-1};\n        }\n        int j = k;\n        while(arr[k] == 0)k++;\n        firstOne = t;\n         while(firstOne <=i){\n            if(arr[firstOne++] != arr[k++])return new int[]{-1,-1};\n        }\n        return new int[]{i,j};\n    }\n}\n```\n
['C++', 'Java', 'Python3']