Question: Question 2 2 Max. score: 2 0 . 0 0 orrect pair sum Given an integer array A of the size N . Find the

Question 22
Max. score: 20.00
orrect pair sum
Given an integer array A of the size N. Find the sum of values in the
array that has different parity from that of their index in the array.
Calculate the sum of values of A[i] for all i where,
A[i]mod2imod2
Note: 1-based indexing is used.
Function description
Complete the function solve. This function takes the following
2 parameters N, and A, and returns an integer output:
N : Represents the number of array elements
A: Represents the integer array A
Input format for custom testing
Note: Use this input format if you are testing against custom input or
writing code in a language where we don't provide boilerplate code.
The first line rontains a sinnle intener I denotina the total Note: Use this input format if you are testing against custom input or
writing code in a language where we don't provide boilerplate code.
The first line contains a single integer T denoting the total
number of test cases.
For each test case:
The first line of each test case contains a single integer
N.
The second line of each test case contains N space-
separated integers representing the array A.
Output format
For each test case in a new line, print a single integer denoting the
answer to the test case.
Constraints
1T10
1N105
1Ai102
Sum of N for all test cases 105 Sample input
2
3
123
4
2345
Explanation
The first line contains T denoting the number of test cases, here T=2.
For the first test case
Given
N=3
A=[1,2,3]
Approach
For i=1, you have A[i]=1,1mod2=1 and imod2=1 Do not add it to
the answer.
For 1=2, you have A(i)=2,2mod2=0 and 1mod2=0. Do not add it
Question 2 2 Max. score: 2 0 . 0 0 orrect pair

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!