There are boxes of different sizes (small, medium, large); a small box fits in a medium and a medium in a large. Implement insertBox(Box b1, Box b2) to insert b1 into b2, and printBoxes() to print all boxes in hierarchical order.
Asked in the LLD round stage. Pair programming; focus on modularity, extensibility and abstractions rather than working code.
Use insertBox(boxes, b1, b2), where boxes maps box IDs to {size, parent} records and parent is either another ID or null. Insert b1 as a child of b2, then return IDs in preorder, starting with each root.
def insertBox(boxes, b1, b2):