You can use this logic to find number of bits set :-

int count = 0;
foreach(int x in array){
  if(x < 0)
    count--; //for the sign bit will be counted below.
  while(x){
    x &= x-1; 
    count++;
  }
}

Thanks
Monish

On Sunday, May 12, 2013 1:05:31 AM UTC+5:30, rahul sharma wrote:
>
> I was searching for google questions and got this question.Use look up to 
> do it in bext way
>
>
> What is best time complexity for this..
> plz post algo too
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to algogeeks+unsubscr...@googlegroups.com.


Reply via email to