package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor/
 */
public class Problem1442 {
    public int countTriplets(int[] arr) {
        int[] xor = new int[arr.length];
        xor[0] = arr[0];
        for (int i = 1; i < arr.length; i++) {
            xor[i] = xor[i - 1] ^ arr[i];
        }
        System.out.println(Arrays.toString(xor));
        int answer = 0;
        for (int i = 0; i < xor.length; i++) {
            for (int j = i + 1; j < xor.length; j++) {
                if ((xor[i] ^ xor[j]) == 0) {
                    answer++;
                }
            }
        }
        return answer;
    }

    public static void main(String[] args) {
        Problem1442 prob = new Problem1442();
        System.out.println(prob.countTriplets(new int[]{2,3,1,6,7})); // 4
//        System.out.println(prob.countTriplets(new int[]{1,1,1,1,1})); // 10
//        System.out.println(prob.countTriplets(new int[]{2,3})); // 0
//        System.out.println(prob.countTriplets(new int[]{1,3,5,7,9})); // 3
//        System.out.println(prob.countTriplets(new int[]{7,11,12,9,5,2,7,17,22})); // 8
    }
}

@@ -16,34 +16,8 @@
 e;%0A%0A
-import java.util.Arrays;%0A%0A
 /**%0A
@@ -218,33 +218,12 @@
 ngth
-%5D;%0A        xor%5B0%5D = arr%5B0
+ + 1
 %5D;%0A 
@@ -249,18 +249,18 @@
  1; i %3C 
-ar
+xo
 r.length
@@ -307,16 +307,20 @@
  %5E arr%5Bi
+ - 1
 %5D;%0A     
@@ -328,58 +328,8 @@
   %7D%0A
-        System.out.println(Arrays.toString(xor));%0A
     
@@ -473,17 +473,16 @@
  if 
-(
 (xor%5Bi%5D 
 %5E xo
@@ -481,17 +481,18 @@
 %5Bi%5D 
-%5E
+==
  xor%5Bj%5D)
  == 
@@ -491,14 +491,8 @@
 %5Bj%5D)
- == 0)
  %7B%0A 
@@ -520,29 +520,22 @@
 swer
-++;%0A                %7D
+ += j - i - 1;
 %0A   
@@ -541,28 +541,22 @@
         
-  %7D%0A
       
-  
 %7D%0A      
@@ -561,510 +561,46 @@
     
-return answer;%0A
     %7D%0A
-%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1442 prob = new Problem1442();%0A        System.out.println(prob.countTriplets(new int%5B%5D%7B2,3,1,6,7%7D)); // 4%0A//        System.out.println(prob.countTriplets(new int%5B%5D%7B1,1,1,1,1%7D)); // 10%0A//        System.out.println(prob.countTriplets(new int%5B%5D%7B2,3%7D)); // 0%0A//        System.out.println(prob.countTriplets(new int%5B%5D%7B1,3,5,7,9%7D)); // 3%0A//        System.out.println(prob.countTriplets(new int%5B%5D%7B7,11,12,9,5,2,7,17,22%7D)); // 8
+    %7D%0A        return answer;
 %0A   

Solve problem 1442