Maximum AND value of a pair in an array | Function for finding maximum and value pair ; Driver function
function maxAND ( arr , n ) { var res = 0 ; for ( var i = 0 ; i < n ; i ++ ) for ( var j = i + 1 ; j < n ; j ++ ) res = Math . max ( res , arr [ i ] & arr [ j ] ) ; return res ; } var arr = [ 4 , 8 , 6 , 2 ] ; var n = arr . length ; document . write ( " " + maxAND ( arr , n ) ) ;