You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
int[] count = new int[31]; // for any positive integer, the msb index can be 0 to 30 in total 31 possibilities, (max int is 2^31 - 1)
long res = 0;
for (int i = 0; i < list.size(); i++) {
int msb = 31 - Integer.numberOfLeadingZeros(list.get(i)); // msb stands for most significant digit, meaning the left most 1, and here we need its index
res += i - count[msb]; // every round we make a pair with all previous numbers, but exclude numbers with same msb index
count[msb]++;
}
return res;
}
public static void main(String[] args) {
XorGreaterThanAndPair sol = new XorGreaterThanAndPair();