Find number of subarrays with even sum
Solutions
Approach - Iterative Technique
public class Solution
{
public int countEvenSum(int[] arr)
{
int result = 0;
for (int i = 0; i < arr.Length; i++)
{
int sum = 0;
for (int j = i; j < arr.Length; j++)
{
sum = sum + arr[j];
if (sum % 2 == 0)
result++;
}
}
return result;
}
} Last updated
