O(N/2) Time complexity Cpp solution

interview-questions
Tags: #<Tag:0x00007f181f761040>

#1

well for even length array its directly 0 and for odd length arr xor even index values.

int Solution::solve(vector<int> &A) {
    int n = A.size();
    if(n&1)
    {
        for(int i=2; i<n; i+= 2) A[0] ^= A[i];
        return A[0];
    }
    return 0;
}