Trains the technique from
LeetCode 1710Maximum Units on a TruckThis 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 nursery wheels plant trays out to the loading dock on a single trolley.
You are given trayTypes, where trayTypes[i] = [count_i, seedlings_i] means the nursery has count_i trays of type i on hand and each of those trays holds exactly seedlings_i seedlings.
The trolley has room for trolleySlots trays altogether. You may put on any mix of types, taking no more of a type than the nursery has, and you are free to leave slots empty.
Return the greatest number of seedlings a single trolley run can carry.
Example 1
Loading all three trays of type 1 at 7 seedlings each and one tray of type 0 at 4 seedlings uses 4 slots and carries 21 + 4 = 25 seedlings.
Example 2
Only 2 slots exist, and loading both trays of type 1 carries 9 + 9 = 18 seedlings.
Example 3
Every tray the nursery has fits, so all 3 trays go on and carry 5 + 8 + 8 = 21 seedlings, leaving 7 slots empty.
Example 4
Types 0 and 1 both hold 6 seedlings per tray, and taking all 4 trays of type 0 plus 3 trays of type 1 fills the 7 slots for 42 seedlings.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def maximum_units(trayTypes: list[list[int]], trolleySlots: int) -> int:public int maximumUnits(int[][] trayTypes, int trolleySlots)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.