Ctrl K

Pack the Delivery Van

Easy
A courier is loading a van with crates. There are several kinds of crates: crates[i] = [count, per_crate] means there are count crates of this kind and each holds per_crate items. The van fits at most capacity crates of any mix of kinds. Crates are never opened: each one is taken whole or left behind. Return the largest number of items the courier can carry in one trip.
Example 1
crates=[[3, 2], [1, 7], [4, 5]], capacity=5 → 27

Take the crate with 7 items and all four crates with 5: 7 + 4 · 5 = 27.

Example 2
crates=[[2, 4], [2, 3]], capacity=10 → 14

There is more room than crates, so everything goes in: 2 · 4 + 2 · 3 = 14.

Example 3
crates=[[5, 1], [1, 9], [2, 6]], capacity=2 → 15
Constraints
  • 1 ≤ len(crates) ≤ 1000
  • 1 ≤ count, per_crate ≤ 1000
  • 1 ≤ capacity ≤ 10⁶
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsCake Slices for Guests EasyStrength of the Weaker Partner EasyTriangle From Sticks EasySign Flips for the Largest Sum EasyPack the Backpack Easy
loading Python…
Input
crates=[[3, 2], [1, 7], [4, 5]], capacity=5
Expected
27

Run checks the first 3 tests in your browser. Submit checks all 105 tests on the server, hidden ones included.