Optimal Division

5

2 votes
, Binary Search, Algorithms
Problem

You have an array of length . You have to divide the array into atmost consecutive segments such that the maximum bitwise OR of these segments is minimum.

Find the minimum possible maximum Bitwise OR of these segments if you divide optimally.

Input Format:

  • The first line contains an integer , denoting the number of test cases.
  • The first line contains two integers, and .
  • The next line contains space-separated integers, elements of array .

Output Format:

For each test case, print the minimum possible maximum Bitwise OR of these segments if you divide optimally.

Constraints:

Sample Input
2
1 1
4
3 2
12 9 7
Sample Output
4
13
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

First test case:
We can divide into . Bitwise OR of these segments is . Hence, the answer is , which is the minimum possible.

Second test case:
We can divide into and . Bitwise OR of these segments is . Hence, the answer is , which is the minimum possible.

Editor Image

?