java.lang.Object
g1401_1500.s1442_count_triplets_that_can_form_two_arrays_of_equal_xor.Solution

public class Solution extends Object
1442 - Count Triplets That Can Form Two Arrays of Equal XOR.<p>Medium</p> <p>Given an array of integers <code>arr</code>.</p> <p>We want to select three indices <code>i</code>, <code>j</code> and <code>k</code> where <code>(0 <= i < j <= k < arr.length)</code>.</p> <p>Let&rsquo;s define <code>a</code> and <code>b</code> as follows:</p> <ul> <li><code>a = arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1]</code></li> <li><code>b = arr[j] ^ arr[j + 1] ^ ... ^ arr[k]</code></li> </ul> <p>Note that <strong>^</strong> denotes the <strong>bitwise-xor</strong> operation.</p> <p>Return <em>the number of triplets</em> (<code>i</code>, <code>j</code> and <code>k</code>) Where <code>a == b</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> arr = [2,3,1,6,7]</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> The triplets are (0,1,2), (0,2,2), (2,3,4) and (2,4,4)</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> arr = [1,1,1,1,1]</p> <p><strong>Output:</strong> 10</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= arr.length <= 300</code></li> <li><code>1 <= arr[i] <= 10<sup>8</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • countTriplets

      public int countTriplets(int[] arr)