AND PRODUCT

CAN ANYONE EXPLAIN THE LOGIC BEHIND IT.

static long andProduct(long a,long b) {
if(a == 0){
return 0;
}
long moveFactor = 0;
while(a != b){
a >>= 1;
b >>= 1;
moveFactor++;
}
return a << moveFactor;
}

Try checking. The editorial

1 Like