Piyush and Bitwise-operation
All submissions for this problem are available.
Piyush learnt bitwise-operation recently. He got very fascinated about bitwise-operation for its wonderful uses. But his girlfriend is not sure of that he has enough skills to solve bitwise-operation problem. So, she decides to test his skills by giving a problem. She gave N non-negative integers A1, A2,...AN, and asks him to find the pair of integers such that AND operation on that pair of integers is maximum.
AND is a bit-wise operation which is corresponding to & in C++ and Java.
- The first line of the input contains an integer T denoting the number of test cases.
- The first line of each test case contains a single integer N. The next line contains N numbers denoting the Ai.
- 1 ≤ T ≤ 100
- 2 ≤ N ≤ 10^5
- 0 ≤ Ai ≤ 10^9
Print a single integer which is the largest value of Ax AND Ay where 1 ≤ x < y ≤ N.
Input: 1 5 2 3 4 5 8 Output: 4
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
Fetching successful submissions