human
Print pair with maximum AND value 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.
Find the elements.
print the pair of elements.
inc count value after printing element.
return the result value.
Driver function"
How can the above be solved in Python?
 ... Can you provide a code to print pair with maximum AND value in an array and the other steps required?
assistant
#Here is code to print pair with maximum AND value 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 += 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 |= ( 1 << bit )
	if ( res == 0 ) :
		print ( " Not ▁ Possible " )
	else :
		print ( " Pair ▁ = ▁ " , end = " " )
		count = 0
		i = 0
		while ( i < n and count < 2 ) :
			if ( ( arr [ i ] & res ) == res ) :
				count += 1
				print ( arr [ i ] , end = " ▁ " )
			i += 1
	return res
arr = [ 4 , 8 , 6 , 2 ]
n = len ( arr )
print ( " Maximum AND Value =   " , maxAND ( arr , n ) )