Timer is Running

Maximize XOR
Submissions: 7   Accuracy:

28.57%

  Difficulty: Easy   Marks: 2

Given a number X find the total numbers A such that A XOR X >= X,  and 1<=A<=X.
 

Example 1:

Input: 10
Output: 5
Explanation: Calculating XOR of 10 with
{1, 4, 5, 6} give values greater than 
equal to 10.

Example 2:

Input: 5
Output: 2
Explanation: Calculating XOR of 5 with 
{2, 3} give values greater than 5.

 

Your Task:
You don't need to read or print anything. Your task is to complete the function maximize_xor_count() which takes X as input parameter and returns total numbers A.

 

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

 

Constraints:
1 <= X <= 108

** For More Input/Output Examples Use 'Expected Output' option **

Author: ShivamKD


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.