Given an array A1,A2...AN. We have to tell how many pairs (i, j) exist such that 1 ≤ i < j ≤ N and Ai XOR Aj is odd.
Example : If N=3 and array is [1 2 3] then here answer is 2 as 1 XOR 2 is 3 and 2 XOR 3 is 1. So, 2 valid pairs.
Problem is that N can be upto 10^5.So how to do it. Please help
Hint: Note that $A_i \text{ XOR } A_j$ is odd precisely when $A_i$ and $A_j$ have opposite parity. So count the odd and even numbers in your array... This gives you an $O(n)$ algorithm instead of $O(n^2)$