Suppose that we have several squares of the same size. We want to draw n rectangles (red and yellow rectangles here) to contain these squares.
The goal is to have the least wasted space possible.
In the example below, n = 2 and the solution on the right is preferred because it only results in one wasted space.
Sorry for my ignorance, but what type of problem is this? Are there any known algorithms already in place?
UPDATE: The arrangement of the squares is arbitrary and they are always above X axis!
UPDATE2: To make the question easier, let's assume that the so called container rectangles are on top of each other! (Red and yellow rectangles here)
A more general case: let's assume two rectangles are used for this one too. As it can be seem the 3rd solution results in the least wasted space.

