Smallest number whose set bits are maximum in a given range | Returns smallest number whose set bits are maximum in given range . ; driver code
function countMaxSetBits ( left , right ) { while ( ( left | ( left + 1 ) ) <= right ) left |= left + 1 ; return left ; } let l = 1 , r = 5 ; document . write ( countMaxSetBits ( l , r ) + " " ) ; l = 1 , r = 10 ; document . write ( countMaxSetBits ( l , r ) ) ;