Find range of values for S in given Array with values satisfying [ arr [ i ] = floor ( ( i * S ) / K ) ] | Function to find the range of values for S in a given array that satisfies the given condition ; Stores the left range value ; Stores the right range value ; Find the current left range value for S ; Find the current right range value for S ; Updating L value ; Updating R value ; Driver code
function findRange ( arr , N , K ) { let L = Number . MIN_VALUE ; let R = Number . MAX_VALUE ; for ( let i = 0 ; i < N ; i ++ ) { let l = Math . ceil ( 1.0 * arr [ i ] * K / ( i + 1 ) ) ; let r = Math . ceil ( ( 1.0 + arr [ i ] ) * K / ( i + 1 ) ) - 1 ; L = Math . max ( L , l ) ; R = Math . min ( R , r ) ; } document . write ( L + " " + R ) ; } let arr = [ 2 , 4 , 6 , 9 , 11 ] ; let K = 10 ; let N = arr . length ; findRange ( arr , N , K ) ;