Count how many distinct XOR values can be formed by choosing three elements from the array.
Given an integer array nums, choose any three indices i, j, and k with i < j < k. Compute the value nums[i] XOR nums[j] XOR nums[k] for each such triplet.
Your task is to return the number of distinct XOR results that can be obtained from all valid triplets.
A result is considered distinct by its value, not by the indices that produced it.
Input Format
- An integer array
nums. - You may assume the array contains at least three elements.
Output Format
- Return an integer: the count of unique values produced by XOR-ing every triplet of distinct indices.
Constraints
- .
- Elements are integers.
- Count each XOR value once, even if many triplets produce it.
- Indices must be distinct and ordered as
i < j < k.
Example 1
Input
nums = [1, 2, 3]
Output
1
Explanation
Only one triplet exists: (1, 2, 3). Its XOR is 1 XOR 2 XOR 3 = 0, so there is exactly one distinct result.
Example 2
Input
nums = [1, 2, 3, 4]
Output
4
Explanation
The triplets produce XOR values {0, 1, 2, 7}. The number of unique results is 4.
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.