Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Count Partitions with Even Sum Difference

XPChallenge Points: 10
levelLevel: Easy

You are given an array nums of length n.

We choose a position i such that:

  • Left part = nums[0] to nums[i]

  • Right part = nums[i+1] to nums[n-1]

Both parts must contain at least one element.

A partition is valid if:

(sum of left subarray) - (sum of right subarray)

is even.

Return how many such valid partitions exist.

Example 1:

Input: nums = [4, 1, 3, 2]

Output: 3

Explanation:

[4], [1,3,2] → 4 - 6 = -2 (even) ✅ [4,1], [3,2] → 5 - 5 = 0 (even) ✅ [4,1,3], [2] → 8 - 2 = 6 (even) ✅ → Actually count = 3 Revised Output: 3

Example 2:

Input: nums = [1,1,1,1]

Output: 3

Explanation:

All splits yield even sum difference.

Example 3:

Input: nums = [5,9]

Output: 1

Explanation:

Only split: [5], [9] → 5 - 9 = -4 (even) → Actually 1 valid Updated Output: 1

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result