Company: JPMorgan Chase

Difficulty: medium

Problem Statement

Longest Valid XOR Subsequence A subsequence of an array is formed by removing zero or more elements without changing the order of the remaining elements. A subsequence is valid when the bitwise XOR of every pair of adjacent elements equals k . A subsequence of length 1 is invalid, regardless of the value of k , because it contains no adjacent pair. The empty subsequence is invalid for the same reason. Given an integer array arr of size n and an integer k , return the length of the longest valid subsequence. If no valid subsequence exists, return 0 . Function maxSubsequenceLength(n: int, arr: int[], k: int) -> int Input format Line 1: a single integer n , the size of the array. Line 2: n space-separated integers, the elements of arr . Line 3: a single integer k . Output format Print a single integer: the length of the longest valid subsequence, or 0 if there is none. Constraints 1 <= n <= 20000 0 <= arr[i] <= 10^6 0 <= k <= 10^6 Examples ### Example 1 Input: 5 2 1 3

More JPMorgan Chase OA questionsInterview experiences