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
Software Engineering Fundamentals
Software Engineer
Amazon
November 29, 2026
Software Engineer
Phone Screen
Software Engineering Fundamentals
Easy

0

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
OOP
Polymorphism
Abstract Classes
Interfaces
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. 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 Problems
Sample 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
  • Container abstract base: name, abstract volume() and fits(dims).
  • Box(l, w, h), Tube(length, diameter), Envelope(l, w, max_thickness).
  • pick_container(containers, dims) filters wit...

Submit Your Answer
Markdown supported