The shape of a box is a square. The volume for a square is lengthxwidthxheight.
For the first box it would be 2x3x6 or 36in.
For the second box, 3x4, which is 12.
Dividing 36 by 12, we get 3.
So 3x4x3 would result in 36in., the same as the first box.