Given a number where, . The task is to find the minimum number of elements to be deleted in between to such that the XOR obtained from the remaining elements is maximum.
Input: N = 5 Output: 2 Input: 1000000000000000 Output: 1
Approach: Considering the following cases:
Case 1: When or , then answer is 0. No need to remove any element.
Case 2: Now, we have to find a number which is power of 2 and greater than or equal to .
Let’s call this number be .
So, if or then we will just remove . Hence the answer is 1.
else if , then answer is 0. No need to remove any element.
Case 3: Otherwise, if is , then answer is 1.
else if is , then answer is 2.
Below is the implementation of above approach:
Time complexity: O(logn)
- Minimum number of elements that should be removed to make the array good
- Find the minimum number of elements that should be removed to make an array good
- Minimum number of elements to be removed so that pairwise consecutive elements are same
- Minimum digits to be removed to make either all digits or alternating digits same
- Minimum size substring to be removed to make a given string palindromic
- Number of digits to be removed to make a number divisible by 3
- Shortest subarray to be removed to make all Array elements unique
- Size of smallest subarray to be removed to make count of array elements greater and smaller than K equal
- Print digit's position to be removed to make a number divisible by 6
- Python | Number of elements to be removed such that product of adjacent elements is always even
- Minimum Bitwise XOR operations to make any two array elements equal
- Minimum number of digits to be removed so that no two consecutive digits are same
- Minimum labelled node to be removed from undirected Graph such that there is no cycle
- Maximum XOR value of maximum and second maximum element among all possible subarrays
- Minimize count of array elements to be removed to maximize difference between any pair up to K
- Maximize sum of array elements removed by performing the given operations
- Minimum operations to make XOR of array zero
- Minimum insertions to make XOR of an Array equal to half of its sum
- Find XOR of two number without using XOR operator
- Count of elements to be inserted to make Array sum twice the XOR of 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.