java.lang.Object
g2501_2600.s2527_find_xor_beauty_of_array.Solution

public class Solution extends Object
2527 - Find Xor-Beauty of Array.<p>Medium</p> <p>You are given a <strong>0-indexed</strong> integer array <code>nums</code>.</p> <p>The <strong>effective value</strong> of three indices <code>i</code>, <code>j</code>, and <code>k</code> is defined as <code>((nums[i] | nums[j]) & nums[k])</code>.</p> <p>The <strong>xor-beauty</strong> of the array is the XORing of <strong>the effective values of all the possible triplets</strong> of indices <code>(i, j, k)</code> where <code>0 <= i, j, k < n</code>.</p> <p>Return <em>the xor-beauty of</em> <code>nums</code>.</p> <p><strong>Note</strong> that:</p> <ul> <li><code>val1 | val2</code> is bitwise OR of <code>val1</code> and <code>val2</code>.</li> <li><code>val1 & val2</code> is bitwise AND of <code>val1</code> and <code>val2</code>.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,4]</p> <p><strong>Output:</strong> 5</p> <p><strong>Explanation:</strong></p> <p>The triplets and their corresponding effective values are listed below:</p> <ul> <li> <p>(0,0,0) with effective value ((1 | 1) & 1) = 1</p> </li> <li> <p>(0,0,1) with effective value ((1 | 1) & 4) = 0</p> </li> <li> <p>(0,1,0) with effective value ((1 | 4) & 1) = 1</p> </li> <li> <p>(0,1,1) with effective value ((1 | 4) & 4) = 4</p> </li> <li> <p>(1,0,0) with effective value ((4 | 1) & 1) = 1</p> </li> <li> <p>(1,0,1) with effective value ((4 | 1) & 4) = 4</p> </li> <li> <p>(1,1,0) with effective value ((4 | 4) & 1) = 0</p> </li> <li> <p>(1,1,1) with effective value ((4 | 4) & 4) = 4</p> </li> </ul> <p>Xor-beauty of array will be bitwise XOR of all beauties = 1 ^ 0 ^ 1 ^ 4 ^ 1 ^ 4 ^ 0 ^ 4 = 5.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [15,45,20,2,34,35,5,44,32,30]</p> <p><strong>Output:</strong> 34</p> <p><strong>Explanation:</strong> <code>The xor-beauty of the given array is 34.</code></p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>5</sup></code></li> <li><code>1 <= nums[i] <= 10<sup>9</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • xorBeauty

      public int xorBeauty(int[] arr)