![]() |
VOOZH | about |
Given an array A[] of length N. Then your task is to output the minimum possible bitwise XOR that can be obtained by removing at mostone element.
Examples:
Input: N = 4, A[] = {2, 4, 3, 6}
Output: 0
Explanation: If we element 3 is removed from A[], then up updated A[] will be: {2, 4, 6}. Then cumulative bitwise XOR = (2^4^6) = 0. Which is minimum possible.Input: N = 2, A[] = {1, 1}
Output: 0
Explanation: No need to remove any element. Bitwise XOR is minimum already.
Approach: We can solve this problem using below idea:
First calculate the XOR of all elements in A[] in a variable let say X. Then iterate on A[] using loop and find the minimum possible value of (X^Ai) among all iterations.
Steps were taken to solve the problem:
Below is the implementation of the above idea:
14
Time Complexity: O(N)
Auxiliary Space: O(1)