Maximum OR value of a pair in an Array | Set 2 | C # implementation of the approach above ; 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
using System ; using System . Linq ; class GFG { static int maxOR ( int [ ] arr , int n ) { int max_value = arr . Max ( ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans = Math . Max ( ans , ( max_value arr [ i ] ) ) ; } return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 6 , 8 , 16 } ; int n = 4 ; Console . Write ( maxOR ( arr , n ) ) ; } }