You are viewing a single comment's thread. Return to all comments →
int sansaXor(vector arr) { int n = arr.size(); if (n % 2 == 0) return 0; // If n is even, result is always 0
int ans = 0; for (int i = 0; i < n; i += 2) { // XOR only odd-positioned elements ans ^= arr[i]; } return ans; }
Seems like cookies are disabled on this browser, please enable them to open this website
Sansa and XOR
You are viewing a single comment's thread. Return to all comments →
int sansaXor(vector arr) { int n = arr.size(); if (n % 2 == 0) return 0; // If n is even, result is always 0