FastPrepBitwise XOR Subsequences
Problems/Bitwise XOR Subsequences

Bitwise XOR Subsequences

JP Morgan Chase logoJP Morgan Chase● MediumOA

Updated Aug 2026

QuestionFunctionExamplesConstraints

Problem statement

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.

Given an integer array arr of size n and an integer k, return the length of the longest valid subsequence.

Function

maxSubsequenceLength(n: int, arr: int[], k: int) → int

Examples

Example 1

n = 5arr = [2, 1, 3, 5, 2]k = 2return = 2

The subsequence [1, 3] is valid because 1 XOR 3 = 2. No valid subsequence is longer than 2. For example, [2, 1, 3] is invalid because 2 XOR 1 is not 2.

Example 2

n = 3arr = [1, 1, 1]k = 0return = 3

The entire array is valid because every adjacent pair is (1, 1) and 1 XOR 1 = 0.

Constraints

  • 1 <= n <= 10^5
  • 0 <= arr[i] <= 10^6
  • 0 <= k <= 10^6

More JP Morgan Chase Online Assessment questions

  • Find Total CostOA · Seen Oct 2026
  • Minimum Meeting RoomsOA · Seen Oct 2026
  • Count Dropped RequestsOA · Seen Oct 2026
  • Maximize Minimum Deployment DifficultyOA · Seen Oct 2026
  • Task SchedulingOA · Seen Oct 2026
  • Substring RemovalOA · Seen Oct 2026
  • Maximum Game Board ScoreOA · Seen Sep 2026
  • Minimum Digit Changes Between String HalvesOA · Seen Sep 2026
  • Same Substring Within BudgetOA · Seen Sep 2026
  • Invert Ad Visibility BitsOA · Seen Aug 2026

Similar questions at other companies

  • Bitwise XOR SubsequencesGoldman Sachs · OAGoldman Sachs interview questions
  • Optimize Discount Selection Under a Point BudgetPalantir · OAPalantir interview questions
  • Maximum Escape Game ScoreMicrosoft · OAMicrosoft interview questions
  • Maximum Points by Deleting ElementsIBM · OAIBM interview questions
  • Vehicle Builds for Required Terrain (Game Adaptation)Roblox · OARoblox interview questions
  • Maximum Points by Deleting ElementsWalmart · OAWalmart interview questions
  • Count Valid Bitwise PairsStripe · OAStripe interview questions
  • Get Maximum ScoreAtlassian · OAAtlassian interview questions
  • Count Subarrays With Given XORInMobi · OAInMobi interview questions
  • Longest Common Contiguous String SequenceIntuit · OAIntuit interview questions

JP Morgan Chase interview experiences

  • JPMorgan Chase Experienced SWE Java Interview: 1 Experience
  • JPMorgan Quant Stats Superdays: 3 Experiences (Part 3 of 3)
  • JPMorgan Quant Modeling Superdays: 7 Experiences (Part 2 of 3)
  • JPMorgan Quant Intern Superday: 19 Experiences (Part 1 of 3)
  • JP Morgan Chase Data and AI Intern Superday: 11 Experiences
  • JPMorgan Code for Good India 2024: 6 Experiences (Part 5 of 5)
All JP Morgan Chase interview questionsSee JP Morgan Chase hiring insights
Saved
class Solution {
    public int maxSubsequenceLength(int n, int[] arr, int k) {
      // write your code here
    }
}
Checking account…