Find XOR of Subarray AND's
Anonymous User
260

I recently came across this question. Given an array of integers we have to find the bitwise XOR of bitwise AND of all the subarrays of size atmost K.

INPUT

N = 5
A = [5,7,8,2,6]
K = 3
OUTPUT

9
Explanation: The possible bitwise AND of subarrays having size atmost 3 are -

[5,5] = 6
[4,4] = 2 , [4,5] = 2
[3,3] = 8 , [3,4] = 0 , [3,5] = 0
[2,2] = 7 , [2,3] = 0 , [2,4] = 0
[1,1] = 5 , [1,2] = 5 , [1,3] = 0

The XOR of all ANDS = 6^2^2^8^0^0^7^0^0^5^5^0 = 9.

Given N <= 1e5 , K <= N , A[i] <= 1e5. Can someone guide on how to solve this problem.

Comments (0)