All Tracks Basic Programming Bit Manipulation Basics of Bit Manipulation Problem

Jarvis and Lone Integer
Tag(s):

Basic Programming, Bitwise-xor, Easy, Easy

Problem
Editorial
Analytics

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. Jarvis is upset too and he wants to prove that it was not his mistake. Help Jarvis to prove himself faithful and true AI.

To 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. Two 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.)

NOTE: 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.)

INPUT:
First 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.

OUTPUT:
For each test output one lone integer or -1 if it doesn't exist.

CONSTRAINTS:
$$1 <= T <= 500$$
$$1 <= N <= 10^5$$
$$1 <= A_i <= 10^{12}$$

SAMPLE INPUT
2  
7  
8 7 8 1 6 6 7  
2  
5 5
SAMPLE OUTPUT
1
-1
Explanation

$$1.$$ In the first test, 8, 7 and 6 can be paired with respected same valued decimal integers, while 1 is left alone.
$$2.$$ In the second test, 5 can be paired with other 5 hence there is no lonely integer. So, the output will be $$-1$$.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Scala 2.11.8, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

IIIT Jabalpur

Challenge Name

Beginner Practice Round 1.0

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications