Code is working good but doubt is that inside the while loop what if the last bit is 1 (ex- 101)and (ans&1) is not zero(101&1 == 1), then the loop should not work and our position remains zero as we initialized it.so my question is how it is also working for these numbers, pls pls pls resolve my doubt please., the code link is in the description.
Doubt in the section of bit masking unique number 2 question
1 << 0
will give mask == 1
so then the entire code works
by finding mask & ai
but what is position, we want position of last bit 1 (from right) but in this case (101) we are getting first position.
we are starting pos = 0
hence since we do not go inside the while loop
hence after pos = 0
1 << pos -> will give 1
1 Like
Thank you, understood that we cAN TAKE ANY SET BIT.
**
THANK YOU VERY MUCH .
**
1 Like
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.