← 返回 goldmansachs 的题目列表Bitwise XOR Subsequences
类型:online_judge
Given an array of integers and an integer k, determine the length of the longest contiguous subsequence that has a XOR result of k. The function must return the length of the longest contiguous subsequence whose XOR of all the adjacent elements equals k.
Example:
Input: n = 5, arr = [1, 3, 5, 2], k = 2 Output: 2
The subarray [1,3] is valid because XOR of adjacent elements is 1 AND 3 (1 XOR 3) equals k.
Function Description:
Complete the function maxSubsequenceLength with the following parameters:
int arr[]: the array
int k: target XOR result
Return:
int: the maximum length of contiguous subsequence whose XOR of all the adjacent elements is k.
Constraints:
1 ≤ n ≤ 10^5
1 ≤ arr[i] ≤ 10^9
0 ≤ k ≤ 10^9
Example
Input
5
1 3 5 2
2