XOR Count Zero and One
Basic Accuracy: 53.66% Submissions: 41 Points: 1

Given a number N, the task is to find XOR of count of 0s and count of 1s in binary representation of a given number.
 

Example 1:

Input: N = 5
Output: 3
Explanation: 
Binary representation: 101
Set_bit_count: 2
Unset_bit_count: 1
2 XOR 1 = 3

Example 2:

Input: N = 7
Output: 3
Expalanation:
Binary representation: 111
Set_bit_count: 3
Unset_bit_count: 0
3 XOR 0 = 3

Your Task:
You don't need to read or print anything. Your task is to complete the function find_xor() which takes N as input parameter and returns the XOR of count of 0s and count of 1s in binary representation of N.

Expected Time Complexity: O(log(N))
Expected Space Complexity: O(1)

Constranits:
1 <= N <= 109

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.