Count how many ways to split an array into two parts so that the difference between their sums is even.
You are given an integer array nums. Count the number of ways to split the array into two groups, usually thought of as a left part and a right part, such that the difference between the sum of the two groups is even.
A split is considered different if the chosen set of elements on one side differs. Elements may be grouped based on the problem's partitioning rule, and you must count all valid partitions that satisfy the parity condition.
Return the total number of valid partitions.
nums of length n.nums is the only input.
1 <= n <= $10^{5}$ in typical interview settingsnums[i] may be positive, zero, or negative unless otherwise specifiedExample 1
Input
nums = [1, 2, 3]
Output
2
Explanation
The total sum is 6. Valid partitions are those where the two parts have sums with an even difference. For this array, two such splits satisfy the condition.
Example 2
Input
nums = [2, 4, 6]
Output
4
Explanation
All elements are even, so every non-empty split into two parts has sums with even difference.
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.