D. Chandler And Jokes - I

4

1 votes
Bit manipulation, Subarrays, Easy
Problem

Chandler is going to perform at his friend's wedding ceremony. He has decided to entertain the audience using his collection of jokes.

He has n jokes in his mind. Phoebe knows the rating of each of these jokes.

Chandler asked Phoebe to select a contiguous subarray for him to perform at the ceremony. As Phoebe is angry with Chandler for unknown reasons, she has decided to select a contiguous subarray which has the least rating.

The overall rating of a contiguous subarray is the bitwise-AND(&) of the ratings of all the jokes present in that contiguous subarray.

Bitwise AND of two numbers x and y is x & y. (& can be used as shift+7)

Help Phoebe by finding the least rating Chandler can have at the ceremony.

What is Contiguous Subarray? :

Contiguous Subarray of an array means all continuous subsets of that array (continuous elements of an array).

Refer: link

For e.g. : Consider an array {2, 1, 2} then different possible contiguous subarrays are:- {2}, {1}, {2}, {2, 1}, {1, 2}, {2, 1, 2}. We can't consider {2, 2} as a subarray because it is not contiguous (as the elements are not continuous in original array).

See the sample case for better understanding.


Input format:

First line contains an integer T, denoting the number of test-cases.

Each testcase consists of 2 lines as shown below:-

First line contains an integer n.

Second line contains n integers (r1, r2, ...rn). Here, ri denotes rating of ith joke.


Output format:

For each testcase, print the minimum rating that Chandler can have.


Constraints:

1 <= t <= 5

1 <= n <= 1000000

1 <= ri <= 1000000000 (10^9)

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

In first testcase, ratings considering different possible subarrays are as follows:-
Rating of {3} = 3
Rating of {5} = 5
Rating of {7} = 7
Rating of {3, 5} = 3 & 5 = 1
Rating of {5, 7} = 5 & 7 = 5
Rating of {3, 5, 7} = 3 & 5 & 7 = 1
As least rating is 1, answer is 1.

In second testcase, only one subarray {7} is possible and so answer is 7.

Editor Image

?