O(n) Java Runtime: 2 ms, faster than 87.50% of Java online submissions
\npublic int[] threeEqualParts(int[] arr) {\n        int oneCount = 0;\n        int n = arr.length;\n        for(int t : arr){\n            if(t == 1) oneCount+
```\npublic int[] threeEqualParts(int[] arr) {\n        int oneCount = 0;\n        int n = arr.length;\n        for(int t : arr){\n            if(t == 1) oneCount++;\n        }\n        if(oneCount == 0) return new int[]{0,n-1};\n        if(oneCount % 3 != 0) return new int[]{-1,-1};\n        int averageOneCount = oneCount / 3;\n        int start = 0;\n        int mid = 0;\n        int end = 0;\n        int cnt = 0;\n        for(int i = 0;i<n;i++){\n            if(arr[i] == 0) continue;\n            if(cnt == 0) {\n                start = i;\n            }\n            cnt++;\n            if(cnt == averageOneCount + 1) {\n                mid = i;\n            }\n            if(cnt == 2 * averageOneCount + 1) {\n                end = i;\n            }\n        }\n        while(end < n && arr[start] == arr[mid] && arr[mid] == arr[end]){\n            start++;\n            mid++;\n            end++;\n        }\n        if(end == n) {\n            return new int[]{start-1,mid};\n        }\n        return new int[]{-1,-1};\n    }\n```
['Java']