Non-empty subsets
Practice
2.4 (25 votes)
Arrays
Data structures
1 D
Problem
89% Success 7007 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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\) (\(1 \leq T \leq 1000\)) denoting the number of test cases.
  • The first line of each test case contains an integer \(N (1 \leq N \leq 2 \times 10^5)\) denoting the number of elements in array \(A\).
  • The second line of each test case contains \(N\) space-separated integers of array \(A(0 \leq A_i \lt 2^{31})\).

Note: It is guaranteed that sum of \(N\) over all test cases is less than or equal to \(2 \times 10^5\).

Output format

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

Constraints

\(1 \leq T \leq 1000\)

\(1 \leq N \leq 2 \times 10^5\)

\(0 \leq A_i < 2^{31} \)

Sum of \(N\) over all test cases is less than or equal to \(2 \times 10^5\)

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:10
113 votes
Tags:
ArraysData Structures1-DC++
Points:10
869 votes
Tags:
Ad-HocApprovedData StructuresEasyOne-dimensional
Points:10
337 votes
Tags:
1-D arrayArraysData Structures