[
accumulate
counter
]
BinarySearch 0914 Number of Sublists With Odd Sum
Problem statement
https://binarysearch.com/problems/Number-of-Sublists-With-Odd-Sum/
Solution
Equal to Leetcode 0974. Subarray Sums Divisible by K.
Complexity
It is O(n)
for time and O(1)
for space.
Code
class Solution:
def solve(self, nums):
acc = [0] + list(accumulate(nums))
cnt = Counter()
for x in acc:
cnt[x%2] += 1
return (cnt[0] * cnt[1]) % (10**9 + 7)