Count Partitions with Even Sum Difference
You receive an integer array nums of length n .
A partition is defined as an index i where 0 <= i < n - 1 , splitting the list into two non-empty subarrays such that:
-
Left sublist contains indices
[0, i]. -
Right sublist contains indices
[i + 1, n - 1].
Produce the number of partitions where the difference between the sum of the left and right subarrays is even .
Input: nums = [10,10,3,7,6]
Output: 4
Explanation: The 4 partitions are:
-
[10],[10, 3, 7, 6]with a sum difference of10 - 26 = -16, which is even. -
[10, 10],[3, 7, 6]with a sum difference of20 - 16 = 4, which is even. -
[10, 10, 3],[7, 6]with a sum difference of23 - 13 = 10, which is even. -
[10, 10, 3, 7],[6]with a sum difference of30 - 6 = 24, which is even.
Input: nums = [1,2,2]
Output: 0
Explanation: No partition results in an even sum difference.
Input: nums = [2,4,6,8]
Output: 3
Explanation: All partitions result in an even sum difference.
Constraints
2 <= n == nums.length <= 1001 <= nums[i] <= 100
Did this problem appear in one of your interviews?
Responses stay private.
