Find XOR of Subarray AND's

Revision en2, by WATER_BOTTLE, 2021-10-03 17:17:12

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. For example-

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

OUTPUT 9

Explanation: The possible bitwise AND of subarrays having size almost 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.

Tags bit manipulation

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English WATER_BOTTLE 2021-10-03 17:23:59 2 Tiny change: 'ing size almost 3 are' -> 'ing size atmost 3 are'
en3 English WATER_BOTTLE 2021-10-03 17:20:01 74
en2 English WATER_BOTTLE 2021-10-03 17:17:12 2 Tiny change: ' of size almost K.\nF' -> ' of size atmost K.\nF'
en1 English WATER_BOTTLE 2021-10-03 17:16:40 614 Initial revision (published)