Number of Sub-arrays With Odd Sum

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 10^9 + 7.

Example 1
Inputarr = [1,3,5]
Output4
Odd subarray sums are 1, 9, 3, and 5, so the answer is 4.
Example 2
Inputarr = [2,4,6]
Output0
All subarrays have even sums, so the answer is 0.

Constraints

  • 1 <= arr.length <= 10^5
  • 1 <= arr[i] <= 100

Asked at 6 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate