Tap here to switch tabs
Problem
Submissions

Problem: Number of Alternating XOR Partitions

Try to solve the Number of Alternating XOR Partitions problem.

Statement

Given an integer array nums and two integers target1 and target2, find the number of ways to partition nums into one or more contiguous non empty subarrays such that the bitwise XOR sum of the elements in each subarray alternates between target1 and target2.

Specifically, the partition must satisfy the following conditions:

  • The first subarray has a bitwise XOR sum equal to target1.

  • The second subarray, if present, has a bitwise XOR sum equal to target2.

  • The third subarray, if present, has a bitwise XOR sum equal to target1, and the values continue alternating in this pattern for all subsequent subarrays.

Return the total number of valid alternating XOR partitions.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 0≤0 \leq nums[i], target1, target2 ≤105\leq 10^5

  • target1 ≠\neq target2

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Alternating XOR Partitions

Try to solve the Number of Alternating XOR Partitions problem.

Statement

Given an integer array nums and two integers target1 and target2, find the number of ways to partition nums into one or more contiguous non empty subarrays such that the bitwise XOR sum of the elements in each subarray alternates between target1 and target2.

Specifically, the partition must satisfy the following conditions:

  • The first subarray has a bitwise XOR sum equal to target1.

  • The second subarray, if present, has a bitwise XOR sum equal to target2.

  • The third subarray, if present, has a bitwise XOR sum equal to target1, and the values continue alternating in this pattern for all subsequent subarrays.

Return the total number of valid alternating XOR partitions.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 0≤0 \leq nums[i], target1, target2 ≤105\leq 10^5

  • target1 ≠\neq target2