human
Maximum AND value of a pair in an array | Utility function to check number of elements having set msb as of pattern.
Function for finding maximum and value pair.
iterate over total of 30 bits from msb to lsb.
find the count of element having set msb.
if count >= 2 set particular bit in result.
Driver function"
Solution in Python:
 ... What is a code to maximum AND value of a pair in an array and the other steps required?
assistant
#Here is code to maximum AND value of a pair in an array and the other steps required.
 def checkBit ( pattern , arr , n ) :
	count = 0
	for i in range ( 0 , n ) :
		if ( ( pattern & arr [ i ] ) == pattern ) :
			count = count + 1
	return count
def maxAND ( arr , n ) :
	res = 0
	for bit in range ( 31 , - 1 , - 1 ) :
		count = checkBit ( res | ( 1 << bit ) , arr , n )
		if ( count >= 2 ) :
			res = res | ( 1 << bit )
	return res
arr = [ 4 , 8 , 6 , 2 ]
n = len ( arr )
print ( " Maximum ▁ AND ▁ Value ▁ = ▁ " , maxAND ( arr , n ) )