Tree of Many Leaves
Practice
4.2 (11 votes)
Operator
Mathematics
Approved
Easy
Mathamatics
Problem
76% Success 2034 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Consider a complete binary tree with N leaves. Every node of the tree stores a positive value. The tree has been built in such a way that every internal node of the tree has a value that is xor of the values of it's two children.

You are given N integers, denoting the values of the N leaves. Find and print the value at the root node.

It can be proven that this value can be uniquely determined.

Input Format

The first line will consist of an integer T, denoting the number of test cases.

Each of the T test cases that follow, will consist of two lines.

The first line for each test case will consist of the integer N.

The second line for each test case will consist of N space separated integers \(A_1, A_2, ... , A_N\) , where \(A_i\) denotes the value in the \(i^{th}\) leaf.

Output Format

For each of the T test cases, print the value at the root node in a new line.

Constraints

\( 1 \le T \le 100 \)

\( 2 \le N \le 1000 \)

\( 1 \le A_i \le 10^9 \)

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:20
1 votes
Tags:
Easy
Points:20
1 votes
Tags:
EasySimple-math
Points:20
1 votes