Maximum length of the subsequence such that XOR of each consecutive element is equal to k

Revision en1, by abhinavxd, 2020-11-08 21:54:27

Find the maximum length of the subsequence such that XOR of each consecutive element is equal to k. example: [3,2,4,3,5] and k=1. Answer = 3, subsequence = [3,2,3]

And for [1,2,5,7,9,8,5] ans would be 3.

So far I have tried these approaches :

A naive two-loop solution where we will use two loops and find the subsequence with XOR equals to k. 2.Second I am thinking of dynamic programming where I can store XOR of already calculated subsequence but I am not able to complete the algorithm.

Can someone please tell me some other way of solving this problem?

Thanks

Tags #bitmasks, xor subarray

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English abhinavxd 2020-11-08 21:55:13 4 Tiny change: 'ls to k.\n2.Second' -> 'ls to k.\n\n\n2.Second'
en1 English abhinavxd 2020-11-08 21:54:27 670 Initial revision (published)