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 XOR of remaining elements
- 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 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
- Count of Array elements to be divided by 2 to make at least K elements equal
- Construct an Array of size N in which sum of odd elements is equal to sum of even elements
- Check if Array elements can be maximized upto M by adding all elements from another array
- 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
- Minimum distance between any two equal elements in an Array
- Check if an array of 1s and 2s can be divided into 2 parts with equal sum
- Minimum cost to make all array elements equal
- Count elements less than or equal to a given value in a sorted rotated array
- Count pairs in an array such that both elements has equal set bits
- Minimum operation to make all elements equal in array
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