-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXorTriplets.java
More file actions
34 lines (30 loc) · 895 Bytes
/
Copy pathXorTriplets.java
File metadata and controls
34 lines (30 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//Given an array of integers arr.
//
// We want to select three indices i, j and k where (0 <= i < j <= k < arr.length).
//
// Let's define a and b as follows:
//
// a = arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1]
// b = arr[j] ^ arr[j + 1] ^ ... ^ arr[k]
// Note that ^ denotes the bitwise-xor operation.
//
// Return the number of triplets (i, j and k) Where a == b.
//Example:
// Input: arr = [2,3,1,6,7]
// Output: 4
// Explanation: The triplets are (0,1,2), (0,2,2), (2,3,4) and (2,4,4)
public class XorTriplets {
public int countTriplets(int[] arr) {
int count=0;
for (int i = 0; i < arr.length-1; i++)
{
for(int j=i+1;j<arr.length;j++)
{
for(int k=j;k<arr.length;k++)
{
}
}
}
return count;
}
}