Load the Most Storage Units Onto a Truck With Limited Box Slots
Last updated: November 29, 2026
Quick Overview
A data center truck can carry at most a fixed number of boxes. Given box types as (count, units per box), return the maximum total storage units the truck can carry.
0
0
0 solved
A data center truck can carry at most a fixed number of boxes. Given box types as (count, units per box), return the maximum total storage units the truck can carry.
Google online assessments include warm-up greedy questions like this to check sorting and careful partial counts. The interviewer expects you to fill with the densest box type first and stop exactly at capacity.
What the Interviewer Expects
- Sort box types by units per box descending
- Take as many of each type as capacity allows
- Stop once capacity is used
- Explain why density-first is optimal
- O(n log n) time
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Units per box are bounded (1 to 1000); do it without a comparison sort.
- Boxes also have weight with a weight cap: now what?
- Return how many of each type were loaded.
- The truck makes multiple trips with different capacities.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: box_types as [count, units] pairs and truck_size, the maximum number of boxes. Every box takes one slot regardless of type. Output: maximum total units....
High-Level Design
Since every box uses one slot, each slot should hold the box with the most units available. Sort by units descending and greedily take min(count, remaining) boxes of each type.
This is a knapsack w...