. , , , , - , , . , ( ) - .
, y- , x- , .
Iterate over your array of rectangles. For each rectangle, initialize the y-coordinate of the rectangle by 0. Then loop, increasing this yy coordinate of the rectangle until it intersects with any of the previously placed rectangles (you need to track which rectangles were previously placed). Lock the y coordinate you just found and continue to process the next rectangle.
source
share