Non-empty subsets

2.4

25 votes
Arrays, Data Structures, 1-D
Problem

You are given an array A consisting of N non-negative integers. Find out the minimum number K such that there exists a non-empty subset of A for which the bitwise OR of all its elements is equal to K.

Input format

  • The first line contains an integer T (1T1000) denoting the number of test cases.
  • The first line of each test case contains an integer N(1N2×105) denoting the number of elements in array A.
  • The second line of each test case contains N space-separated integers of array A(0Ai<231).

Note: It is guaranteed that sum of N over all test cases is less than or equal to 2×105.

Output format

For each test case, print a line containing the minimum possible value of K.

Constraints

1T1000

1N2×105

0Ai<231

Sum of N over all test cases is less than or equal to 2×105

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?