Remove minimum elements from the array such that 2 * min becomes more than max | Function to calculate upper bound ; Function to remove minimum elements from the array such that 2 * min becomes more than max ; Sort the array ; To store the required answer ; Traverse from left to right ; Update the answer ; Return the required answer ; Driver code ; Function call
function upperBound ( array , value ) { var low = 0 ; var high = array . length ; while ( low < high ) { var mid = parseInt ( ( low + high ) / 2 ) ; if ( value >= array [ mid ] ) { low = mid + 1 ; } else { high = mid ; } } return low ; } function Removal ( v , n ) { v . sort ( ( a , b ) => a - b ) ; var ans = 2147483648 ; var k = 0 ; for ( const i of v ) { var j = upperBound ( v , 2 * i ) ; ans = Math . min ( ans , n - ( j - k ) ) ; k ++ ; } return ans ; } var a = [ 4 , 5 , 100 , 9 , 10 , 11 , 12 , 15 , 200 ] ; var n = a . length ; document . write ( Removal ( a , n ) ) ;