Most efficient way to get Least Significant not set bit and Most Significant not set bit

41 Views Asked by At

I have a binary string, say 10111101111 and I want the Most significant not set bit i.e the first 0 starting from the left and the Least significant not set bit i.e. the first 0 from the right.

Basically indices of these two 0s in: 1 0 1111 0 1111

I know the O(n) approach, is there a more efficient way to get these indices?

0

There are 0 best solutions below