Jarvis and Lone Integer

QUESTION

Today Tony Stark is upset with Jarvis, as it blew the whole plan of him defeating the Flash in parallel universe by showing him two images of Flash. Tony couldn’t identify the real one and ended up getting hit hard. \n\nJarvis is upset too and he wants to prove that it was not his mistake. Help Jarvis to prove himself faithful and true AI.\n\nTo prove, that Jarvis is not at fault, he is given N non-negative integers and he has to identify a lone integer among them. A lone integer is defined as an integer in the given array of integers that is left alone after pairing each of the other integers. \n\nTwo integers can be paired if they have same value in decimal number system and have different indices in the array. (Look at example case for better understanding and it is guaranteed that there is at most one such integer.)\n\nNOTE: An integer can’t be paired with itself and once paired it can’t be used to pair with other integers. (There are spaces after each input.)\n\nINPUT:\nFirst line will contain T, number of times Jarvis tests itself. For each test there will be two lines. First line of each test will contain number of integers N he takes, and next line will have N non-negative integers.\n\nOUTPUT:\nFor each test output one lone integer or -1 if it doesn’t exist.\n\nCONSTRAINTS:\n \n1<=T<=500\n1<=N<=10^5\n 1<=Ai<=10^12.

ANSWER

#include <stdio.h>
 
#define testcase(T) for(scanf("%lld", &T); T; --T)
 int i;
long long s, temp, T, N;
 
int main() {
 testcase(T) {
  s = 0;
  scanf("%lld", &N);
  for(i = 0; i < N; i++) {
   scanf("%lld", &temp);
   s = s ^ temp;
  }
  if(s == 0) {
   printf("-1\n");
  } else {
   printf("%lld\n", s);
  }
 }
 return 0;
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.