Maximum length of all possible K equal length ropes generated by cutting N ropes | Function to find the maximum size of ropes having frequency at least K by cutting the given ropes ; Stores the left and the right boundaries ; Stores the maximum length of rope possible ; Iterate while low is less than or equal to high ; Stores the mid value of the range [ low , high ] ; Stores the count of ropes of length mid ; Traverse the array arr [ ] ; If count is at least K ; Assign mid to ans ; Update the value of low ; Otherwise , update the value of high ; Return the value of ans ; Driver Code
function maximumSize ( a , k ) { let low = 1 ; let high = Math . max . apply ( Math , a ) ; let ans = - 1 ; while ( low <= high ) { let mid = Math . floor ( low + ( high - low ) / 2 ) ; let count = 0 ; for ( let c = 0 ; c < a . length ; c ++ ) { count += Math . floor ( a / mid ) ; } if ( count >= k ) { ans = mid ; low = mid + 1 ; } else { high = mid - 1 ; } } return ans ; } let arr = [ 1 , 2 , 3 , 4 , 9 ] ; let K = 6 ; document . write ( maximumSize ( arr , K ) )