Find the number of sub-arrays having even sum
Submissions: 2279   Accuracy:

52.02%

  Difficulty: Easy   Marks: 2

Given an array  A[]  you have to  find the number of subarrays whose sum is an even number.
 

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. 
The first line  of each test case contains an integer N, where N is the size of the array A[ ] .
Then Next line contains space seperated N value of the array A[ ].


Output:
For each test case in a new line, number of sub-arrays having even sum

 

Constraints:
1 <= T <= 200
1 <= N <= 100
1<= A[i] <=100


 

Example:

Input:
1
6
1 2  2  3  4 1

Output:
9

 

Explanation:
In the first test case the array  {1, 2, 2, 3, 4, 1} has 9 such possible subarrays-

These are-

 {1, 2, 2, 3}          Sum = 8

 {1, 2, 2, 3, 4}      Sum as  = 12

 {2}                      Sum as  = 2 (At index 1)

 {2, 2}                  Sum as Sum = 4

 {2, 2, 3, 4, 1}      Sum as = 12

 {2}                      Sum as  = 2 (At index 2)

 {2, 3, 4, 1}          Sum as = 10

 {3, 4, 1}              Sum as  = 8

 {4}                      Sum as = 4

 

** For More Input/Output Examples Use 'Expected Output' option **

Author: Shubham Joshi 1


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.