A XOR operation
Practice
3.7 (14 votes)
Bit manipulation
Bit manipulation
Basics of bit manipulation
Basic programming
Problem
88% Success 6148 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You are given a set \(S\) of distinct positive integers of size \(n\) (\(n\) is always even). Print the minimum positive integer \(k\) that is greater than 0 such that after replacing each element \(e\) of the set \(S\) with \(e⊕k\), set \(S\) remains the same.

Print -1 if there is no such \(k\).

Note: It is guaranteed that \(\frac{n}{2}\) is odd.

Input format

  • The first line contains a single integer \(t\ (1\le t \le 100)\) denoting the number of test cases.
  • The first line of each test case contains a single integer \(n\ (2 \le n \le 1e5)\) denoting the number of elements in the set.
  • The second line of each test case contains \(n\) integers \(e\ (1 \le e \le 1e9)\).

Output format

Print \(t\) lines each containing a single line that contains \(k\).

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
150 votes
Tags:
ReadyBrute-force searchEasy-MediumApprovedBreadth-first search
Points:20
96 votes
Tags:
Basic ProgrammingBit Manipulation
Points:20
26 votes
Tags:
Basic ProgrammingBit ManipulationBit manipulationEasy