Java sol
\nclass Solution {\n    int t;\n    public int[] threeEqualParts(int[] A) {\n        int res[]=new int[]{-1,-1};\n        int part1=0;int part2=0;int part3=0;in
```\nclass Solution {\n    int t;\n    public int[] threeEqualParts(int[] A) {\n        int res[]=new int[]{-1,-1};\n        int part1=0;int part2=0;int part3=0;int cnt=1;\n        Map<Integer,Integer>map=new HashMap<>();\n        int ones=0;\n        for(int n:A)if(n==1)ones++;\n        if(ones==0)return new int[]{0,A.length-1};\n        if(ones%3!=0)return res;\n        t=ones/3;ones=0;\n        for(int i=0;i<A.length;i++){\n            if(A[i]==1){\n                ones++;\n                map.put(cnt,i);\n                cnt++;\n            }\n        }\n        for(int i=map.get(t)+1;i<=map.get(2*t);i++){\n            if(A[i]==0)part1++;\n            else break;\n        }\n        for(int i=map.get(2*t)+1;i<A.length;i++){\n            if(A[i]==0)part2++;\n            else break;\n        }\n        for(int i=map.get(ones)+1;i<A.length;i++){\n            if(A[i]==0)part3++;\n        }\n        if(part1<part3||part2<part3)return res;\n        List<Integer>l1=getlist(A,map.get(1),map.get(t));\n        List<Integer>l2=getlist(A,map.get(t+1),map.get(2*t));\n        List<Integer>l3=getlist(A,map.get(2*t+1),map.get(ones));\n        if(!compare(l1,l2)||!compare(l2,l3))return res;\n        res[0]=map.get(t)+part3;\n        res[1]=map.get(2*t)+part3+1;\n        return res;\n    }\n    \n    public List<Integer> getlist(int A[],int i1,int i2){\n        List<Integer>list=new ArrayList<>();\n        for(int i=i1;i<=i2;i++)list.add(A[i]);\n        return list;\n    }\n    public boolean compare(List<Integer>list1,List<Integer>list2){\n        if(list1.size()!=list2.size())return false;\n        for(int i=0;i<list1.size();i++){\n            if(list1.get(i)!=list2.get(i))return false;\n        }\n        return true;\n    }\n}\n```
[]