Maximum OR value of a pair in an Array | Set 2 | Function to return the maximum bitwise OR for any pair of the given array in O ( n ) time complexity . ; Find the maximum element in the array ; Stores the maximum OR value ; Traverse the array and perform Bitwise OR between every array element with the maximum element ; Driver Code
function maxOR ( arr , n ) { let max_value = Math . max ( ... arr ) ; let ans = 0 ; for ( let i = 0 ; i < n ; i ++ ) { ans = Math . max ( ans , ( max_value arr [ i ] ) ) ; } return ans ; } let arr = [ 3 , 6 , 8 , 16 ] ; let n = 4 ; document . write ( maxOR ( arr , n ) ) ;