How to make this code work for negative numbers

I tried this program for [-2,-2,1,1,-3,1,-3,-3,-4,-2]
but this is not working for this data set.

well it should work! can you share the code


Take type as long long (for -ve integers are represented as 2’s complement!)

bhaiya i was trying same question another platform if you could help for it, even after chnaging to long long it isnt working.
question: https://leetcode.com/problems/single-number-ii/submissions/
my soln: https://ide.codingblocks.com/s/268671

Don’t use a while loop!


moreover here long long is not necessary as input fits into int(32 bit)

ohhhh okayy we are not using while(n>0) becuase no.s are already negavite they will all be <0 ?

but the code above which was taught in the cb video uses while no>0 and works fine for negavite numbers, what is the logic behind not using while(no>0)

Yes you will not count bits in that case!

There must be some modification (if it works) because you have implemented yourself and seen the failure.

how do one gets to know the mistake they are doing? like i was doing it well but somehow failed in the analysis part while debugging how not to do these mistakes?

Dear Naman, there is no formula to it, it comes naturally by lots of practice.

okayyy, thanks a lot. Will work on this then.

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.