As reported: Goldman Sachs online assessment (2026), second coding question: "Bitwise XOR Subsequences".
Given an integer array arr and an integer k, a subsequence (elements kept in their original order, not necessarily contiguous) is valid if every pair of adjacent elements in it has XOR equal to k. A subsequence of length 1 is always valid. Return the length of the longest valid subsequence.
Example 1
arr = [2,1,3,5,2], k = 2
-> 2 [1,3] is valid (1 XOR 3 = 2); [2,1,3] is not (2 XOR 1 = 3)
Example 2
arr = [1,3,1,3,1], k = 2
-> 5 the whole array alternates 1, 3
Constraints: 1 ≤ arr.length ≤ 10^5; 0 ≤ arr[i], k < 2^30.
Code runner format: one JSON value per line: arr, then k. Implement longestXorSubsequence(arr, k); the harness prints the length.