Dividing space into smaller areas

I’d recommend taking a look at this thread: https://discourse.mcneel.com/t/fitting-rectangles-into-larger-area, and in particular the solution by @laurent_delrieu.

Then consider that from a construction perspective it will be less costly if you restrict the range of dimensions of the apartments. Also that things that go into apartments have typical sizes, so building on a modular size around them will be efficient. Make a range of rectangles representing your apartment shapes and use them in the grasshopper solution, with a surface that represents your building space.

Finally, I’d recommend setting the corridor before calculating the apartments. For efficiency you don’t want it winding around, so set it straight as possible and work the apartments off it.

HTH
Jeremy