Only Premium Users can view the Question
You are given an integer array A of size N. Your task is to count and print the number of XOR-AND inversions in array A. A pair (‘i’, ‘j’) is said to be an XOR-AND inversion if and only if it satisfies the following conditions:
The input consists of two lines:
Input will be read from the STDIN by the candidate
Print the count of XOR-AND inversions.
Output will be matched to the candidate’s output printed on the STDOUT
5
7 12 16 10 6
2
There are only two pairs that satisfies both the conditions those are
Hence the output is 2.
6
2 4 32 8 16 64
0
Q1)
Given : A[i]&A[j]>=A[i]^A[j] and let's check for the most significant bit of A[i] and A[j] let it be at xth and yth position from right respectively.
If x is not equal to y then XOR will be always greater than AND .
If x is equal to y then AND will be greater because XOR's corresponding bit would be unset, which means same number of set bits.
Hence we need to just count pairs with same count of bits.