[LeetCode] Number of Unique XOR Triplets I

3513. Number of Unique XOR Triplets I

You are given an integer array nums of length n, where nums is a permutation of the numbers in the range [1, n].

A XOR triplet is defined as the XOR of three elements nums[i] XOR nums[j] XOR nums[k] where i <= j <= k.

Return the number of unique XOR triplet values from all possible triplets (i, j, k).

A permutation is a rearrangement of all the elements of a set.

1
2
3
4
5
6
7
8
class Solution {
public:
int uniqueXorTriplets(vector<int>& nums) {
int n = nums.size();
return n <= 2 ? n : pow(2, 64 - __builtin_clzll(n));
}
};

Author: Song Hayoung
Link: https://songhayoung.github.io/2025/04/13/PS/LeetCode/number-of-unique-xor-triplets-i/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.