Your free access ends in 7 days — and you haven’t tried it yet. Watch one algorithm run, start to finish. It takes about two minutes.

Try one problem
0
Problem

Minimum Shipping Capacity

LeetCode #1011Medium
Ship packages in D days · search the capacity

Given package weights that must be shipped in their given order, find the minimum ship capacity such that all packages can be shipped within a given number of days, where each day loads consecutive packages without exceeding the capacity.

Asked atAmazonGoogle
step 1 / 12
3
2
2
4
1
4
[0][1][2][3][4][5]
Brute force · grow the ship one unit at a time
1given weights, D
2for cap = max(w), max(w)+1, …:
3 days = greedy-load at cap
4 if days ≤ D: return cap
5// first fit is minimal
state
  • days3
  • total16

line 1Ship these packages IN ORDER within 3 days. The ship has one capacity; each day it loads packages until the next one would not fit. Smallest capacity that makes the deadline? Brute: try 1, 2, 3, …