Minimum size binary string required such that probability of deleting two 1 's at random is 1/X | Function returns the minimum size of the String ; From formula ; Left limit of r ; Right limit of r ; Smallest integer in the valid range ; Driver Code
function MinimumString ( x ) { let b = 1 ; let left_lim = Math . sqrt ( x ) + 1.0 ; let right_lim = Math . sqrt ( x ) + 2.0 ; let r = 0 ; for ( let i = Math . floor ( left_lim ) ; i <= Math . floor ( right_lim ) ; i ++ ) { if ( i > left_lim && i < right_lim ) { r = i ; break ; } } return b + r ; } let X = 2 ; document . write ( MinimumString ( X ) ) ;