Simple O(n) logical approach explained with example
Approach \n  The array has to contain number of 1\'s that are multiple of 3\n  Each of the three parts has to contain equal number of ones\n  Now it\'s all abou
### Approach \n*  The array has to contain number of 1\'s that are multiple of 3\n*  Each of the three parts has to contain equal number of ones\n*  Now it\'s all about locating the beginning of 1s, and comparing the parts\n\n### Example\n```\n    000010101010000101010100001010101      << example\n    [0]*1[1,0]*[0]*1[1,0]*[0]*1[1,0]*      << pattern\n        ^          ^          ^            << beginning of first 1 in each part\n        <--n-->    <--n-->    <--n-->      << n = length of the last part \n        left       middle     right        << left, middle, right parts whose value is to be compared\n               ^          ^                << beginning of each part, having leading 0s\n              i           j                << answer = end of first part, beginning of last part\n```\n\n### Python3 Implementation\n* `O(n)` time\n\t* one pass for counting 1\'s\n\t* one pass for locating the first 1 of each part\n\t* one pass for comparing left, middle and right parts\n* `O(1)` space \n\t* ignores space taken by string splicing\n\t* we can always do that in `O(1)` time with a little bit of extra lines of code\n\n```\n    def threeEqualParts(self, arr: List[int]) -> List[int]:\n        \n        ones = sum(arr)         # total count of 1\'s\n        \n        # early termination conditions\n        if ones % 3 != 0: return [-1, -1]\n        if ones == 0:     return [0, len(arr)-1]\n        \n        cnt = 0                  # running count of 1\'s\n        target1 = 1              # first 1 of left part\n        target2 = 1 + ones//3    # first 1 of middle part\n        target3 = 1 + 2*ones//3  # first 1 of right part\n        \n        for idx, bit in enumerate(arr):\n            if bit == 1:\n                cnt += 1\n                if cnt == target1: start1 = idx\n                if cnt == target2: start2 = idx\n                if cnt == target3: start3 = idx\n\n        n = len(arr) - start3\n        if arr[start1 : start1+n] == arr[start2 : start2+n] == arr[start3 : start3+n]:\n            return [start1 + n - 1, start2 + n]  \n        \n        return [-1, -1]\n```
['Python3']