Minimum number of Circular obstacles required to obstruct the path in a Grid | Function to find the minimum number of obstacles required ; Find the minimum range required to put obstacles ; Sorting the radius ; If val is less than zero then we have find the number of obstacles required ; Driver function
function solve ( n , m , obstacles , range ) { var val = Math . min ( n , m ) ; range . sort ( ( a , b ) => a - b ) var c = 1 ; for ( var i = obstacles - 1 ; i >= 0 ; i -- ) { range [ i ] = 2 * range [ i ] ; val -= range [ i ] ; if ( val <= 0 ) { return c ; } else { c ++ ; } } if ( val > 0 ) { return - 1 ; } } var n = 4 , m = 5 , obstacles = 3 ; var range = [ 1.0 , 1.25 , 1.15 ] ; document . write ( solve ( n , m , obstacles , range ) + " " ) ;