Given an array arr, the task is to check if sum of all elements of an array is equal to XOR of all elements of array.
Input: arr = [1, 2]
Sum = (1+2) = 3
XOR = (1^2) = 3
Input: arr = [6, 3, 7, 10]
Sum = (6 + 3 + 7 + 10) = 26
XOR = (6 ^ 3 ^ 7 ^ 10) = 8
- Iterate over the Array and find sum of all elements.
- Similarly, XOR all the elements of the array.
- Check if sum and xor value is equal.
Below is the implementation of the above approach:
Time Complexity: O(n)
- Maximum sum of Bitwise XOR of all elements of two equal length subsets
- Check if the array has an element which is equal to XOR of remaining elements
- XOR of all elements of array with set bits equal to K
- Split an Array A into Subsets having equal Sum and sizes equal to elements of Array B
- Minimizing array sum by applying XOR operation on all elements of the array
- Check if there exist two elements in an array whose sum is equal to the sum of rest of the array
- Count of elements which are equal to the XOR of the next two elements
- Count ways to make Bitwise XOR of odd and even indexed elements equal by removing an array element
- Given a set, find XOR of the XOR's of all subsets.
- Check if the array has an element which is equal to sum of all the remaining elements
- Construct an Array of size N in which sum of odd elements is equal to sum of even elements
- Minimum Bitwise XOR operations to make any two array elements equal
- Construct an array from XOR of all elements of array except element at same index
- Sum of XOR of sum of all pairs in an array
- Sum of elements in 1st array such that number of elements less than or equal to them in 2nd array is maximum
- Minimum insertions to make XOR of an Array equal to half of its sum
- Count of elements to be inserted to make Array sum twice the XOR of Array
- Position of Elements which are equal to sum of all Preceding elements
- Index of the elements which are equal to the sum of all succeeding elements
- Equal Sum and XOR
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 : AnkitRai01