All problems
0124MediumArrayBinary Search

Kiln Load Ceiling

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1011Capacity To Ship Packages Within D Days

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A ceramics studio has one kiln and a queue of unfired pieces. The queue is given as masses, where masses[i] is the clay mass in grams of the piece standing at position i. Pieces leave the queue from the front only, so they are fired in exactly the listed order and are never rearranged.

The studio has booked sessions kiln runs. A single run takes some number of pieces off the front of the queue, which means each run fires one contiguous block of the queue, and it may take none at all. The kiln is rated for a load ceiling: the combined mass loaded into any one run may not exceed it.

Return the smallest load ceiling for which sessions runs are enough to fire the entire queue. A run is never split across sessions, and a piece is never fired twice.

Examples

Example 1

Input
masses = [9, 4, 6, 3, 8], sessions = 3
Output
11

With a ceiling of 11 the runs can be 9 | 4, 6 | 3, 8. Dropping to 10 forces the trailing 3 and 8 apart, which needs a fourth run.

Example 2

Input
masses = [5, 5, 5, 5], sessions = 4
Output
5

Four runs are booked for four pieces, so each run can hold one piece and the ceiling only has to cover the heaviest piece.

Example 3

Input
masses = [2, 4, 6, 1], sessions = 1
Output
13

A single run must swallow the whole queue, so the ceiling equals the total mass of 13 grams.

Constraints

  • 1 <= sessions <= masses.length <= 5 * 10^4
  • 1 <= masses[i] <= 500

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def kiln_load_ceiling(masses: list[int], sessions: int) -> int:
Java
public int kilnLoadCeiling(int[] masses, int sessions)
September 7
Apply