I am trying to solve a problem in which I am dividing a list stick into equal size given by K.
Input: stick = [5, 9, 7], K = 4
This means that we have three sticks with lengths as 5, 9 and 7. We would like to come up with K=4 equal length sticks by cutting these three sticks. We would like to end up with K=4 equal length sticks.
From the first stick with length 5, we can have one stick with length 4.
From the second stick with length 9, we can have two sticks with length 4.
From the third stick with length 7, we can have one stick with length 4. For example:
Input: stick = [5, 9, 7], K = 4
Output: 4
Explanation:
Cut arr[0] = 5 = 4 + 1
Cut arr[1] = 9 = 2 * 4 + 1
Cut arr[2] = 7 = 4 + 3
Example 2:
Input: stick[] = {5, 9, 7}, K = 3
Output: 5 \
Explanation:
Cut arr[0] = 5 = 5
Cut arr[1] = 9 = 5 + 4
Cut arr[2] = 5 = 5 + 2
Trying to create a logic what is best possible method, how we can divide them into K equal parts.