[
accumulate
dp
]
BinarySearch 0841 Equalize Even and Odd Index Sums
Problem statement
https://binarysearch.com/problems/Equalize-Even-and-Odd-Index-Sums/
Solution
Equal to Leetcode 1664. Ways to Make a Fair Array.
Complexity
It is O(n)
for time and space.
Code
class Solution:
def solve(self, A):
n = len(A)
for i in range(1, n, 2): A[i] = -A[i]
acc = [0] + list(accumulate(A))
return sum(acc[i+1] + acc[i] == acc[-1] for i in range(n))