![]() |
VOOZH | about |
Odious number is a nonnegative number that has an odd number of 1s in its binary expansion. The first few odious numbers are therefore 1, 2, 4, 7, 8, 11, 13, 14, 16, 19...
Given a number check if its a odious number or not.
Examples :
Input : 16 Output : Odious Number Explanation: Binary expansion of 16 = 10000, having number of 1s =1 i.e odd. Input : 23 Output : Not odious number Explanation: Binary expansion of 23 is 10111, the number of 1s in this is 4 i.e even.
1) Count set bits in given number.
2) Return true if the count is odd, false otherwise.
Output :
Yes
Time Complexity: O(logn)
Space Complexity: O(1)