MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / Solution

Class Solution

NumberOfSubarraysWithOddSum.java:1–21  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Solution {
2 public int numOfSubarrays(int[] arr) {
3 int Mod=1000000007;
4 int evenC=1;
5 int oddC=0;
6 int prefix=0;
7 int res=0;
8 for(int num : arr){
9 prefix+=num;
10 if(prefix%2==0){
11 res += oddC;
12 evenC++;
13 }else{
14 res += evenC;
15 oddC++;
16 }
17 res = res % Mod;
18 }
19 return res;
20 }
21}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected