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)
- Check if there exist two elements in an array whose sum is equal to the sum of rest of the array
- Check if the array has an element which is equal to sum of all the remaining elements
- Check if the array has an element which is equal to XOR of remaining elements
- Check if the array has an element which is equal to product of remaining elements
- Check if elements of array can be made equal by multiplying given prime numbers
- Sum of elements in 1st array such that number of elements less than or equal to them in 2nd array is maximum
- Check if all the elements can be made equal on dividing with X and Y
- For each element in 1st array count elements less than or equal to it in 2nd array | Set 2
- For each element in 1st array count elements less than or equal to it in 2nd array
- XOR of all elements of array with set bits equal to K
- Make all elements of an array equal with the given operation
- Check if an array of 1s and 2s can be divided into 2 parts with equal sum
- Count of smaller or equal elements in sorted array
- Minimum operation to make all elements equal in array
- Minimum cost to make all array elements equal
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.
Improved By : AnkitRai01