An interesting XOR based Question
Anonymous User
1180

Given an array of N integers and an integer K find the count of the pairs A[i] and A[j] i!=j such that A[i] xor A[j] = X where X lies in between 0 to K.(inclusive)

1<=N,K<=10^5
1<= A[i] <= 10^8

sum(A[i]) for i=1 to N <= 10^8

eg

Input : N = 3, K=2, arr = [1,2,3]
Output : 0 1 1

for X = 0 , No of pairs = 0 s.t A[i]^A[j] = 0
for X = 1 , No of pairs =1, (2,3)
for X = 2 , No of pairs =1 , (1,3)

Please provide some optimized approach less than O(n^2)

Comments (8)