#2527
Find Xor-Beauty of Array
pupil · 565 · lc medium +29 · verified · 70.6% accepted · 394 likes · top 79%
Description
Given a 0-indexed integer array nums of length n, define the effective value of index triplet (i, j, k) as (nums[i] | nums[j]) & nums[k]. The xor-beauty of nums is the XOR of effective values across all triplets where 0 <= i, j, k < n. Return the xor-beauty.
Example 1:
Input: nums = [1,4]
Output: 5
Explanation:
The triplets and their corresponding effective values are listed below:
- (0,0,0) with effective value ((1 | 1) & 1) = 1
- (0,0,1) with effective value ((1 | 1) & 4) = 0
- (0,1,0) with effective value ((1 | 4) & 1) = 1
- (0,1,1) with effective value ((1 | 4) & 4) = 4
- (1,0,0) with effective value ((4 | 1) & 1) = 1
- (1,0,1) with effective value ((4 | 1) & 4) = 4
- (1,1,0) with effective value ((4 | 4) & 1) = 0
- (1,1,1) with effective value ((4 | 4) & 4) = 4
Xor-beauty of array will be bitwise XOR of all beauties = 1 ^ 0 ^ 1 ^ 4 ^ 1 ^ 4 ^ 0 ^ 4 = 5.
Example 2:
Input: nums = [15,45,20,2,34,35,5,44,32,30]
Output: 34
Explanation: The xor-beauty of the given array is 34.
Code
1
2
3