Ctrl K

Even-Gap Cut Points

Easy
Crates stand in a row, and weights lists the weight of each one. The row is cut at a single spot between two neighbouring crates, leaving at least one crate on each side. Return the number of spots where the cut makes the difference between the total weight on the left and on the right an even number.
Example 1
weights=[4, 7, 1, 2] → 3

The cuts give 4 | 10 (difference −6), 11 | 3 (8) and 12 | 2 (10): all three are even.

Example 2
weights=[3, 2, 2] → 0

The cuts give 3 | 4 (−1) and 5 | 2 (3): both differences are odd, so the answer is 0.

Constraints
  • 2 ≤ len(weights) ≤ 10⁵
  • 1 ≤ weights[i] ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTotals of Odd-Length Slices EasyA Stretch Divisible by k MediumThe Growing Grab Limit MediumStretches With k Odd Numbers MediumSplit Into Equal-XOR Halves Medium
loading Python…
Input
weights=[4, 7, 1, 2]
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 92 tests on the server, hidden ones included.