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