P16306 [GeeksforGeeks] 11e021cba210768fe464423e954b3eaf7f2a7c93
普及
题目描述

Due to the rise of covid-19 cases in India, this year BCCI decided to organize knock-out matches in IPL rather than a league.
Today is matchday 4 and it is between one-time champions Rajasthan Royals and the team lead by the Youngest Captian - Delhi Capitals. As this match is very crucial, Rahul Tewatia, Rajasthan Royals all-rounder wants to hit six sixes in an over. But he knows that he can only hit six sixes if he finds the maximum AND value that can be generated by any pair of elements from the given array. Help Tewatia to find the answer.
Note: AND is a bitwise '&' operator.
Example 1:
Input:
N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Explanation:
Pair (8, 12) has the Maximum AND Value 8.
Example 2:
Input:
N = 4
arr[] = {4, 8, 16, 2}
Output: 0
Explanation: Maximum AND Value is 0.
Your Task:
You don't need to read input or print anything. Your task is to complete the function maxAND() which takes the array elements and N (size of the array) as input parameters and returns the maximum AND value generated by any pair in the array.
Constraints:
1 ≤ N ≤ 10^{5}
1 ≤ arr[i] ≤ 10^{5}

输入格式

见题面

输出格式

见题面

样例输入
N = 4 arr[] = {4, 8, 12, 16}
样例输出
8