Count Partitions with Even Sum Difference

You are given an integer array nums of length n.

A partition is defined as an index i where 0 <= i < n - 1, splitting the array into two non-empty subarrays such that:

  • Left subarray contains indices [0, i].
  • Right subarray contains indices [i + 1, n - 1].

Return the number of partitions where the difference between the sum of the left and right subarrays is even.

Example 1
Inputnums = [10,10,3,7,6]
Output4
The 4 partitions all have even sum differences: -16, 4, 10, and 24.
Example 2
Inputnums = [1,2,2]
Output0
No partition results in an even sum difference.

Constraints

  • 2 <= n == nums.length <= 100
  • 1 <= nums[i] <= 100

Asked at 5 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate