All submissions

Solution with Approach

#include <stdio.h>

int validate_checksum(int *mem, int n) {
    // Write your XOR scan logic here
    
    							//	int checksum= mem[n-1];
    int xor_sum=0;
    for(int i=0; i<n-1; i++){
        xor_sum ^= mem[i];
    }
    if (mem[n-1] == xor_sum)  //if(checksum == xor_sum)
        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

  1. Create a variable that stores the iterative XOR of each element till (n-1) element or ((n-2) index element)
  2. Compare it with the last element for equality, if yes return 1, else 0

    if (mem[n-1] == xor_sum)  //if(checksum == xor_sum)
            return 1;
    return 0;

 

 

 

Loading...

Input

5 10 20 30 40 60

Expected Output

0