Skip to content
Decoder

Maximum Units on a Truck

Easy

Problem

box_types[i] = [count, units] means there are count boxes of type i, and each holds units units. The truck carries at most truck_size boxes, of any types. Return the maximum total units you can load.

Example 1

Input
box_types = [[1, 3], [2, 2], [3, 1]], truck_size = 4
Output
8
Why
3 + 2 + 2 + 1

Example 2

Input
box_types = [[5, 10], [2, 5], [4, 7], [3, 9]], truck_size = 10
Output
91

Constraints

  • 1 <= box_types.length <= 1000
  • 1 <= count, units <= 1000
  • 1 <= truck_size <= 10^6

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.