Count how many ways to split an array into three contiguous parts with equal sum.
You are given an array of integers. Count the number of ways to choose two cut points so that the array is split into three non-empty contiguous parts, and the sum of each part is the same.
More formally, for an array of length , count pairs such that:
Return the number of valid splits.
Example 1
Input
5 1 2 3 0 3
Output
2
Explanation
The total sum is 9, so each part must sum to 3. The valid splits are [1,2] | [3] | [0,3] and [1,2] | [3,0] | [3].
Example 2
Input
4 0 0 0 0
Output
3
Explanation
Every part must sum to 0. The valid cut pairs are any two distinct cut points among the 3 available positions, so the number of ways is 3.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.