O(n) O(1) beat 100% simple count and compare 3 part
Approach
count total of arr
separate to 3 part with the same total_part = total/3
compare each index in 3 part, check the same.
return result.
Complexity
Time c
# Approach
- count total of `arr`
- separate to 3 part with the same `total_part = total/3`
- compare each index in 3 part, check the same.
- return result.

# Complexity
- Time complexity: O(n)
- Space complexity:O(1)

# Code
```golang []

func threeEqualParts(arr []int) []int {
	total := 0
	for i := range arr {
		total += arr[i]
	}
	if total%3 != 0 {
		return []int{-1, -1}
	}
	if total == 0 {
		return []int{0, 2}
	}
	parts := [3][2]int{{-1, 0}, {-1, 0}, {-1, 0}}
	totalPart := 0
	for i := range arr {
		totalPart += arr[i]
		if totalPart == 1 && parts[0][0] == -1 {
			parts[0][0] = i
		}
		if totalPart == total/3+1 && parts[1][0] == -1 {
			parts[1][0] = i
		}
		if totalPart == 2*total/3+1 && parts[2][0] == -1 {
			parts[2][0] = i
			break
		}
	}
	parts[2][1] = len(arr)
	partLength := parts[2][1] - parts[2][0]
	parts[0][1] = parts[0][0] + partLength
	parts[1][1] = parts[1][0] + partLength
	if parts[0][1] > parts[1][0] || parts[1][1] > parts[2][0] {
		return []int{-1, -1}
	}
	for i := 0; i < partLength; i++ {
		if arr[parts[0][0]+i] != arr[parts[1][0]+i] || arr[parts[0][0]+i] != arr[parts[2][0]+i] {
			return []int{-1, -1}
		}
	}
	return []int{parts[0][1] - 1, parts[1][1]}
}

```
['Go']