Problem
Ask
Submissions

Problem: Divide Chocolate

Medium
30 min
Explore how to apply modified binary search to divide a chocolate bar into pieces, maximizing the minimum sweetness that you get. This lesson guides you through problem understanding, constraints, and coding implementation to develop a strategic solution.

Statement

You have a chocolate bar made up of several chunks, and each chunk has a certain sweetness, given in an array called sweetness. You want to share the chocolate with k friends. To do this, you’ll make k cuts to divide the bar into k + 1 parts. Each part will consist of consecutive chunks.

Being a kind person, you’ll take the piece with the minimum total sweetness and give the other pieces to your friends.

Your task is to find the maximum total sweetness of the piece you will receive if you cut the chocolate bar optimally.

Constraints:

  • 00 \leq k << sweetness.length 103\leq 10^{3}

  • 11 \leq sweetness[i] 103\leq 10^{3}

Problem
Ask
Submissions

Problem: Divide Chocolate

Medium
30 min
Explore how to apply modified binary search to divide a chocolate bar into pieces, maximizing the minimum sweetness that you get. This lesson guides you through problem understanding, constraints, and coding implementation to develop a strategic solution.

Statement

You have a chocolate bar made up of several chunks, and each chunk has a certain sweetness, given in an array called sweetness. You want to share the chocolate with k friends. To do this, you’ll make k cuts to divide the bar into k + 1 parts. Each part will consist of consecutive chunks.

Being a kind person, you’ll take the piece with the minimum total sweetness and give the other pieces to your friends.

Your task is to find the maximum total sweetness of the piece you will receive if you cut the chocolate bar optimally.

Constraints:

  • 00 \leq k << sweetness.length 103\leq 10^{3}

  • 11 \leq sweetness[i] 103\leq 10^{3}