Hey coiner.

This sounds like an optimization problem where you have to minimize the perimeter of the square, whilst keeping all the stuff in.

In a normal optimization for perimeter, we have p = 2x + 2y and A = xy where we wish to minimize p and maximize A.

You will also have to take into account the nature of the blocks.