Maximum Bitwise OR pair from a range | C ++ implementation of the approach ; Function to return the maximum bitwise OR possible among all the possible pairs ; Check for every possible pair ; Maximum among all ( i , j ) pairs ; Driver code
#include <climits> NEW_LINE #include <iostream> NEW_LINE using namespace std ; int maxOR ( int L , int R ) { int maximum = INT_MIN ; for ( int i = L ; i < R ; i ++ ) for ( int j = i + 1 ; j <= R ; j ++ ) maximum = max ( maximum , ( i j ) ) ; return maximum ; } int main ( ) { int L = 4 , R = 5 ; cout << maxOR ( L , R ) ; return 0 ; }