Write a function:classSolution { Public intSolution (int[] A); }that, given an array A consisting of N integers, returns the number of pairs (P, Q) such that0≤p < Q < N and (A[p] + a[q]) is even. The function shouldreturn−1ifThe number of such pairs exceeds 1,000,000,000. For example, given array A such that:a[0] = 2, a[1] = 1, a[2] = 5, a[3] =−6, a[4] = 9The function shouldreturn4, because there is four pairs that fulfill the above condition, namely (0,3), (), (1,4), (2,4). Assume That:n is an integer within the range [0..1,000,000];each element of array A is an integer within the range [−2,147,483,648..2,147,483,647]. Complexity:expected Worst- CaseTime complexity is O (N); expected worst- CaseSpace complexity is O (1), Beyond input storage (not counting the storage required forinput arguments). Elements of input arrays can be modified.
Idea: Nothing is to scan the number of odd and even numbers, for example, M and N, and then the odd selection of two, even inside the selection of two, a odd and even, the answer is M (M-1)/2 + N (N-1)/2 + MN
Twitter OA Prepare:even sum pairs