• + 1 comment
    1. please note that "&" not a logical operator in python. It's a bit-wise operator.
    2. How on earth did you come up with this logic!!!

    a demo of how it works (it took me a while to figure it out so I'm sharing it): say , let's take 5. so, binary(5) = 101 which our n here. for the first loop iteration: n = 101 & 1010 ( 101<<1) = 0000 ans = 1 2nd time n>0 doesn't hold so output is 1