480. Divide Chocolate

You have one chocolate bar that consists of some chunks. Each chunk has its own sweetness given by the array sweetness.

You want to share the chocolate with your k friends so you start cutting the chocolate bar into k + 1 pieces using k cuts, each piece consists of some consecutive chunks.

Being generous, you will eat the piece with the minimum total sweetness and give the other pieces to your friends.

Find the maximum total sweetness of the piece you can get by cutting the chocolate bar optimally.

Example 1:

Input: sweetness = [1,2,3,4,5,6,7,8,9], k = 5

Output: 6

Explanation: You can divide the chocolate to [1,2,3], [4,5], [6], [7], [8], [9]

Example 2:

Input: sweetness = [1,2,2,1,2,2,1,2,2], k = 2

Output: 5

Explanation: You can divide the chocolate to [1,2,2], [1,2,2], [1,2,2]

Now Your Turn!

Pick the correct output for the given input

Input: sweetness = [1,2,3,4,5,6], k = 2

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 0 <= k < sweetness.length <= 104
  • 1 <= sweetness[i] <= 105

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
int maximizeSweetness(vector<int>& sweetness, int k) {
// User code goes here
}
};
Test Case

Input:

K
Sweetness