Skip to main content
LeetCode 1231, Hard. Topics: Array, Binary Search. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 30 parametrized pytest cases, and a playground notebook:

Problem

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 <strong>consecutive</strong> chunks. Being generous, you will eat the piece with the <strong>minimum total sweetness</strong> and give the other pieces to your friends. Find the <strong>maximum total sweetness</strong> of the piece you can get by cutting the chocolate bar optimally.

Examples

Constraints

  • 0 <= k < sweetness.length <= 10<sup>4</sup>
  • 1 <= sweetness[i] <= 10<sup>5</sup>

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026