#include <stdio.h>
int validate_checksum(int *mem, int n) {
// Write your XOR scan logic here
int xor_sum = mem[0];
for(int i = 1; i<n-1; i++){
xor_sum ^= mem[i];
}
if(xor_sum == mem[n-1]) return 1;
return 0;
}
int main() {
int n, arr[100];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
int result = validate_checksum(arr, n);
printf("%d", result);
return 0;
}
Solving Approach
Use a variable to track the XOR of all elements except the last checksum, and use conditional loop to return the value.