- Room is rectangular in nature with dimensions: a X b X c units. Balls are perfectly spherical with radii r units.
- Room has no content (furniture, windows), anything that will not let its volume be 'abc cubic units'.
- Interviewer wishes to know the maximum number of balls I could fit.
- Radius of ball(r) is insignificant compared to room's dimensions(a,b,c). This is important so that max number of balls I could fit will be very significantly greater than a little bit of space left at the ends because of effective radius not being a multiple of a particular dimension. Imagine fitting balls with diameter just greater than half of the length of the largest edge. No matter the packing, you can only fit 1.
- you already don't know from the lattice packing science that says spheres can be tightly packed at best 75% density. A fact already used by someone to answer this question.
Packing and Calculation:
Now, we need to strategise a packing of balls so that we fit maximum.
Imagine laying out balls along a bottom floor edge, say 'c'. The best fit would be to place them in a line side by side. Number of balls I can fit is x = (c/2r).
Now place another line adjacent to it. You want to place it such that a ball in the second line falls between the gap of the 2 balls in the first line for the densest fit. By simple 2D geometry(height of equilateral triangle), the line connecting radii of second line is say h = (root(3)*r).Therefore the number of such lines I can lay out to fill floor is say y = b/h = b/(root(3)*r). Also ignoring the r distance between edge most lines and edge(insignificant compared to b as assumed). (You can ignore the math for the interview I guess).
Now you have a 2D plane of balls on the floor. Next obvious step is to plan the next 2D plane of balls on it to fill the height. This of course needs to be done in such a way that a ball in the second plane is in between the gaps of 3 adjacent balls of the first plane for the tightest packing. Skipping the geometry and math involved, lets say the the distance between the centers of balls of these 2 planes turns out to be some h. The number of such planes I can do is a/h = z(say).
Therefore the number of balls is x*y*z.