Handle Score
@Ibrahim Nash 6420
@blackshadows 6380
@mb1973 5646
@Quandray 5233
@akhayrutdinov 5111
@saiujwal13083 4716
@sanjay05 3762
@kirtidee18 3673
@marius_valentin_dragoi 3522
@sushant_a 3459
@verma_ji 3413
Complete Leaderboard
Maximum AND Value
Medium Accuracy: 44.82% Submissions: 12082 Points: 4

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.

Example 1:

N = 4
arr[] = {4, 8, 12, 16}
Output: 8
Pair (8,12) has the Maximum AND Value 8.

Example 2:

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. 

Expected Time Complexity: O(N * log M), where M is the maximum element of the array.

Expected Auxiliary Space: O(1).


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

to report an issue on this page.


We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?


All Submissions

My Submissions:

Login to access your submissions.

Maximum AND Value

Output Window