[InterviewBit] XOR-ing the Subarrays!

XOR-ing the Subarrays!

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
int Solution::solve(vector<int> &A) {
int res = 0, n = A.size();
for(int i = 0; i < n; i++) {
int req = (i + 1) * (n - i);
if(req & 1) res ^= A[i];
}
return res;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/11/08/PS/Codeforces/xor-ing-the-subarrays/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.