Given an positive integer n and k. Find maximum xor of 1 to n using at most k numbers. Xor sum of 1 to n is defined as 1 ^ 2 ^ 3 ^ … ^ n.
Input : n = 4, k = 3 Output : 7 Explanation Maximum possible xor sum is 1 ^ 2 ^ 4 = 7. Input : n = 11, k = 1 Output : 11 Explanation Maximum Possible xor sum is 11.
If we have k = 1 then the maximum possible xor sum is 1. Now for k > 1 we can always have an number with its all bits set to 1. So result will be maximum number greater than n with its all bits set to 1.
- Maximum XOR of Two Numbers in an Array
- Maximum sum by adding numbers with same number of set bits
- Absolute difference between the XOR of Non-Prime numbers and Prime numbers of an Array
- Maximum XOR value in matrix
- Value in a given range with maximum XOR
- Maximum XOR-value of at-most k-elements from 1 to n
- Find a sub matrix with maximum XOR
- Maximum AND value of a pair in an array
- Maximum value of XOR among all triplets of an array
- Find a value whose XOR with given number is maximum
- Find the maximum subset XOR of a given set
- Maximum XOR value of a pair from a range
- Maximum 0's between two immediate 1's in binary representation
- Find the node whose xor with x gives maximum value
- Find maximum xor of k elements in an array
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Mithun Kumar