Bitwise XOR Subsequences
A subsequence of an array is formed by removing zero or more elements from an array without changing the order of the remaining elements. In a valid subsequence, each pair of adjacent elements of the subsequence has bitwise XOR equal to k. Note that any subsequence of length 1 is valid regardless of the value of k, because there is no pair of adjacent elements in such a subsequence.
Given an array of integers and integer k, determine the length of the longest valid subsequence in the array.
Complete the function maxSubsequenceLength in the editor below. The function must return the length of the longest valid subsequence of the array, given parameter k.
maxSubsequenceLength has the following parameter(s):
int n: the size ofarrint arr[n]: an array of integersint k: an integer
Constraints
- 1 ≤
n≤ 10^5 - 0 ≤
arr[i]≤ 10^6 - 0 ≤
k≤ 10^6
Input Formatting
In the first line, there is a single integer, n, the number of elements in arr.
Each of the following n lines contains a single integer, arr[i].
In the last line, there is a single integer, k, the value the bitwise XOR of adjacent elements must equal for the subsequence to be valid.
1Example 1
The subsequence [1,3] is valid because for all pairs of adjacent elements it has (1 and 3), the bitwise XOR of such elements is equal to k (1 XOR 3 = 2). There are no other valid subsequences that are longer than 2. For example, subsequence [2,1,3] is not valid because 2 XOR 1 does not equal 2.
Constraints
Limits and guarantees your solution can rely on.