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
- Shortest subarray to be removed to make all Array elements unique
- Number of digits to be removed to make a number divisible by 3
- Print digit's position to be removed to make a number divisible by 6
- Minimum number of elements to be replaced to make the given array a Fibonacci Sequence
- Find the minimum number of operations required to make all array elements equal
- Python | Number of elements to be removed such that product of adjacent elements is always even
- Missing occurrences of a number in an array such that maximum absolute difference of adjacent elements is minimum
- Minimum gcd operations to make all array elements one
- Minimum number of digits to be removed so that no two consecutive digits are same
- Minimum steps to make all the elements of the array divisible by 4
- Make array elements equal with minimum cost
- Minimum cost to make all array elements equal
- Make all the array elements odd with minimum operations of given type
- Minimum operations to make all elements equal using the second array
- Minimum changes required to make all Array elements Prime
- Minimum operations required to make all the array elements equal
- Minimum operations required to make all Array elements divisible by K
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.