Back to problems Sign in to unlock
Leetcode
Medium
Arrays
Hash Maps
Math
Google
Meta
Count Triplets That Can Form Two Arrays Of Equal Xor
Count triplets of indices where two adjacent subarrays have the same XOR.
Acceptance 0%
Problem Statement
Given an array of integers, count the number of triplets such that:
- the XOR of the subarray from index to is equal to the XOR of the subarray from index to
In other words, split a contiguous segment into two non-empty parts with the same XOR and count all valid choices of .
Input Format
- A single integer array
arrof length . - Each value is an integer.
Output Format
- Return the total number of valid triplets satisfying the XOR condition.
Constraints
- for the brute-force friendly interview formulation, though the standard optimized solution works for larger as well.
- Elements are integers in a range that supports XOR operations normally.
- Count all valid index triplets.
Examples
Sample cases returned by the problem API.
Example 1
Input
arr = [2,3,1,6,7]
Output
4
Explanation
The valid triplets are (0,1,2), (0,2,2), (2,3,4), and (2,4,4). Each one splits a subarray into two parts with equal XOR.
Example 2
Input
arr = [1,1,1,1,1]
Output
10
Explanation
Many segments have equal XOR on both sides. Counting all valid index triplets gives 10.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.
Guided hints
Editorial and discussion links
Concept map and variants
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.