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
- 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
- Minimum gcd operations to make all array elements one
- Minimum cost to make all array elements equal
- Make all the array elements odd with minimum operations of given type
- Minimum steps to make all the elements of the array divisible by 4
- Minimum number of digits to be removed so that no two consecutive digits are same
- Minimum operations required to make all the elements distinct in an array
- Minimum Bitwise XOR operations to make any two array elements equal
- Minimum array elements to be changed to make Recaman's sequence
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.