A Graph Theory Problem

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 5.0s
Memory limit: 256M

Author:
Problem types

You are given a complete graph consisting of N nodes, each with a value of v_i. The weight of the edge between nodes a and nodes b is v_a \oplus v_b, where \oplus denotes the XOR operator. You wish to build the Minimum Spanning Tree (MST) of this graph.

Can you output the position of the highest one bit of the heaviest edge in the MST?

Input Specification

The first line will contain T (1 \le T \le 10), the number of test cases. T test cases follow.

For each test case, the first line will contain the integer N (2 \le N \le 10^5), the number of nodes.

The second line will contain N integers, v_i (1 \le v_i \le 10^9).

Output Specification

For each test case, output the position of the highest one bit of the heaviest edge in the MST on its own line, or -1 if there is no ones bit.

Sample Input

2
4
3 7 4 1
2
100 100

Sample Output

2
-1

Explanation for Sample

The heaviest edge's binary representation is 100, whose highest one bit is in position 2 (Note the zero indexing).


Comments

There are no comments at the moment.