Given an array of integers arr, return the number of subarrays with an odd sum. Since the answer can be very large, return it modulo 109+7.
Example 1:
Input: {"arr":[1,2,3,4,5,6,7]}
Output: 16
Constraints:
1≤arr.length≤105
1≤arr[i]≤100
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"arr":[1,2,3,4,5,6,7]}
P0
1
P1
2
P2
3
P3
4
P4
5
P5
6
P6
7
P7
● even prefix● odd prefix
even prefixes
1
odd prefixes
0
odd-sum subarrays
0
A subarray sum is the difference of two prefix sums, and it is odd only when one prefix is odd and the other even. Start with the empty prefix (sum 0), which is even: even = 1, odd = 0.