2527. Find Xor-Beauty of Array Medium

@problem@discussion
#Array#Math#Bit Manipulation



1/**
2 * [2527] Find Xor-Beauty of Array
3 *
4 * You are given a 0-indexed integer array nums.
5 * The effective value of three indices i, j, and k is defined as ((nums[i] | nums[j]) & nums[k]).
6 * The xor-beauty of the array is the XORing of the effective values of all the possible triplets of indices (i, j, k) where 0 <= i, j, k < n.
7 * Return the xor-beauty of nums.
8 * Note that:
9 * 
10 * 	val1 | val2 is bitwise OR of val1 and val2.
11 * 	val1 &amp; val2 is bitwise AND of val1 and val2.
12 * 
13 *  
14 * <strong class="example">Example 1:
15 * 
16 * Input: nums = [1,4]
17 * Output: 5
18 * Explanation: 
19 * The triplets and their corresponding effective values are listed below:
20 * - (0,0,0) with effective value ((1 | 1) &amp; 1) = 1
21 * - (0,0,1) with effective value ((1 | 1) &amp; 4) = 0
22 * - (0,1,0) with effective value ((1 | 4) &amp; 1) = 1
23 * - (0,1,1) with effective value ((1 | 4) &amp; 4) = 4
24 * - (1,0,0) with effective value ((4 | 1) &amp; 1) = 1
25 * - (1,0,1) with effective value ((4 | 1) &amp; 4) = 4
26 * - (1,1,0) with effective value ((4 | 4) &amp; 1) = 0
27 * - (1,1,1) with effective value ((4 | 4) &amp; 4) = 4 
28 * Xor-beauty of array will be bitwise XOR of all beauties = 1 ^ 0 ^ 1 ^ 4 ^ 1 ^ 4 ^ 0 ^ 4 = 5.
29 * <strong class="example">Example 2:
30 * 
31 * Input: nums = [15,45,20,2,34,35,5,44,32,30]
32 * Output: 34
33 * Explanation: The xor-beauty of the given array is 34.
34 * 
35 *  
36 * Constraints:
37 * 
38 * 	1 <= nums.length <= 10^5
39 * 	1 <= nums[i] <= 10^9
40 * 
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/find-xor-beauty-of-array/
45// discuss: https://leetcode.com/problems/find-xor-beauty-of-array/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50    pub fn xor_beauty(nums: Vec<i32>) -> i32 {
51        0
52    }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn test_2527() {
63    }
64}
65


Back
© 2025 bowen.ge All Rights Reserved.