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 ; Stores the maximum OR value the array ; Traverse the array and perform Bitwise OR between every array element with the maximum element ; Driver Code
def maxOR ( arr , n ) : NEW_LINE INDENT max_value = max ( arr ) NEW_LINE ans = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT ans = max ( ans , ( max_value arr [ i ] ) ) NEW_LINE DEDENT return ans NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 3 , 6 , 8 , 16 ] NEW_LINE n = len ( arr ) NEW_LINE print ( maxOR ( arr , n ) ) NEW_LINE DEDENT