Unique no.3 code

check why this code is not working and I want to implement by storing all the number’s in array.

@Gurjot first you should convert the number in its binary form and then add it to the “sum” array

I am storing the bits in sum using the bitwise operators, so why to convert number into binary form.

@Gurjot yeah i did not understand what are you trying to do with that nested loop? I am also suggesting the same approach only, you dont have to necessarily store it somewhere else and then add it to sum, you can directly increment the sum array according to the set bits of each number. But i did not understand why are you using a nested loop.

The outer loop is for incrementing the index of sum array and inner loop is traversing the array in which all the no’s are stored.

@Gurjot change the order of nested loops, run it on the array of numbers, and calculate the bits for each number and store it in sum array. (make 1->n loop outside, and 1->64 loop inside)

https://ide.codingblocks.com/s/269632, I have done like you said, but it again doesn’t work.

@Gurjot you havent taken input for n. Take input and it is giving correct answer.

Thanks,it works well this time

@Gurjot please mark your doubt as resolved :slight_smile:

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.