Model Shipping Box Types With Polymorphic Volume and Fit Checks
Last updated: November 29, 2026
Quick Overview
Design a small class hierarchy for shipping containers (rectangular box, cylindrical tube, padded envelope) that each report their internal volume and whether a product of given dimensions fits inside, so the packing code can pick the smallest container that fits without type checks.
Amazon
November 29, 20260
0
0 solved
Design a small class hierarchy for shipping containers (rectangular box, cylindrical tube, padded envelope) that each report their internal volume and whether a product of given dimensions fits inside, so the packing code can pick the smallest container that fits without type checks.
A fundamentals question in the style of Amazon phone screens checking inheritance versus composition, polymorphism, and clean interfaces. The packaging-selection framing comes up because the caller should never need `isinstance` branches.
What the Interviewer Expects
- Define an abstract Container with volume and fits
- Implement each shape's fit logic correctly, including rotation for boxes
- Select the smallest fitting container polymorphically
- Avoid isinstance checks in the selection code
- Discuss where tolerances and padding live
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you add a new container type supplied by a partner?
- How would you account for packing material thickness?
- How would you choose a container for multiple products?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Product dimensions are (length, width, height) in cm. A box fits if the sorted product dimensions are each <= the sorted box dimensions (rotation allowed). A tube fits if the product's longest side fi...
High-Level Design
Containerabstract base:name, abstractvolume()andfits(dims).Box(l, w, h),Tube(length, diameter),Envelope(l, w, max_thickness).pick_container(containers, dims)filters wit...