java.lang.Object
g1501_1600.s1524_number_of_sub_arrays_with_odd_sum.Solution

public class Solution extends Object
1524 - Number of Sub-arrays With Odd Sum.<p>Medium</p> <p>Given an array of integers <code>arr</code>, return <em>the number of subarrays with an <strong>odd</strong> sum</em>.</p> <p>Since the answer can be very large, return it modulo <code>10<sup>9</sup> + 7</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> arr = [1,3,5]</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> All subarrays are [[1],[1,3],[1,3,5],[3],[3,5],[5]]</p> <p>All sub-arrays sum are [1,4,9,3,8,5].</p> <p>Odd sums are [1,9,3,5] so the answer is 4.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> arr = [2,4,6]</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> All subarrays are [[2],[2,4],[2,4,6],[4],[4,6],[6]]</p> <p>All sub-arrays sum are [2,6,12,4,10,6].</p> <p>All sub-arrays have even sum and the answer is 0.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> arr = [1,2,3,4,5,6,7]</p> <p><strong>Output:</strong> 16</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= arr.length <= 10<sup>5</sup></code></li> <li><code>1 <= arr[i] <= 100</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • numOfSubarrays

      public int numOfSubarrays(int[] arr)