Maximum AND Value
Submissions: 1358   Accuracy:

42.66%

  Difficulty: Easy   Marks: 2

Given an array arr[] of N positive elements. The task is to find the Maximum AND Value generated by any pair of element from the array.
Note: AND is bitwise '&' operator.

Input:
The first line of the input contains a single integer T, denoting the number of test cases. Then T test cases follow. Each test-case has two lines of the input, the first line contains an integer denoting the size of an array N and the second line of input contains N positive integers

Output:
For each testcase, print Maximum AND Value of a pair in a separate line.

Constraints:
1 <=T <= 100

1 <= N <= 5*105
1 <= arr[i] <= 5*105

Example:
Input:
2
4
4 8 12 16
4
4 8 16 2

Output:
8

0

Explanation:
Testcase 1:
Pair (8,12) has the Maximum AND Value  i.e. 8.
Testcase 2: Maximum AND Value is 0.

 

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Sahil Chhabra
Author: Sahil_Chhabra


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.