Prevent Box Overlap in Grasshopper

I want to parametrically make boxes, where box width, length and center point can be controlled. I think the picture show this more clearly than words.

What I need is a way to restrict further increase in length or width if the box intersect any other box. How do it do it?
OnlyGeometry.gh (14.8 KB)

You can sort all X value & Y values and find the maximum than add offset value.

OnlyGeometry_.gh (21.0 KB)

Hello, thank you for getting back to me.

Can you tell where does output of ‘Pt’ component goes? My guess was it goes into “Rectangle - P” but that seems to not work.

Your point are in the definition and disabled
And for simple solution all box are distributed on 2d grid