3513. Number of Unique XOR Triplets I Medium

@problem@discussion
#Array#Math#Bit Manipulation



1/**
2 * [3513] Number of Unique XOR Triplets I
3 *
4 * You are given an integer array nums of length n, where nums is a <span data-keyword="permutation">permutation</span> of the numbers in the range [1, n].
5 * A XOR triplet is defined as the XOR of three elements nums[i] XOR nums[j] XOR nums[k] where i <= j <= k.
6 * Return the number of unique XOR triplet values from all possible triplets (i, j, k).
7 *  
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">nums = [1,2]</span>
11 * Output: <span class="example-io">2</span>
12 * Explanation:
13 * The possible XOR triplet values are:
14 * 
15 * 	(0, 0, 0) &rarr; 1 XOR 1 XOR 1 = 1
16 * 	(0, 0, 1) &rarr; 1 XOR 1 XOR 2 = 2
17 * 	(0, 1, 1) &rarr; 1 XOR 2 XOR 2 = 1
18 * 	(1, 1, 1) &rarr; 2 XOR 2 XOR 2 = 2
19 * 
20 * The unique XOR values are {1, 2}, so the output is 2.
21 * </div>
22 * <strong class="example">Example 2:
23 * <div class="example-block">
24 * Input: <span class="example-io">nums = [3,1,2]</span>
25 * Output: <span class="example-io">4</span>
26 * Explanation:
27 * The possible XOR triplet values include:
28 * 
29 * 	(0, 0, 0) &rarr; 3 XOR 3 XOR 3 = 3
30 * 	(0, 0, 1) &rarr; 3 XOR 3 XOR 1 = 1
31 * 	(0, 0, 2) &rarr; 3 XOR 3 XOR 2 = 2
32 * 	(0, 1, 2) &rarr; 3 XOR 1 XOR 2 = 0
33 * 
34 * The unique XOR values are {0, 1, 2, 3}, so the output is 4.
35 * </div>
36 *  
37 * Constraints:
38 * 
39 * 	1 <= n == nums.length <= 10^5
40 * 	1 <= nums[i] <= n
41 * 	nums is a permutation of integers from 1 to n.
42 * 
43 */
44pub struct Solution {}
45
46// problem: https://leetcode.com/problems/number-of-unique-xor-triplets-i/
47// discuss: https://leetcode.com/problems/number-of-unique-xor-triplets-i/discuss/?currentPage=1&orderBy=most_votes&query=
48
49// submission codes start here
50
51impl Solution {
52    pub fn unique_xor_triplets(nums: Vec<i32>) -> i32 {
53        0
54    }
55}
56
57// submission codes end
58
59#[cfg(test)]
60mod tests {
61    use super::*;
62
63    #[test]
64    fn test_3513() {
65    }
66}
67

Back
© 2026 bowen.ge All Rights Reserved.