Overlapping rooms when creating them from external layout

I am trying to create a set number of random rooms from an external layout every time the player is in collision with doors (blue rectangles). The logic in that is straightforward, where if player is in collision with the door there are few possibilities of what kind of room is going to be created. Room with only left and right doors, room with only top doors, room with doors on all 4 walls and so on… Once the room is created, it stays there until scene restarts and player can go back and forth in already created rooms.

Since there are many possibilities of creating rooms, at some point there will be conflict in terms of what kind of a room is allowed to be created as they will start looping into each other.

Right now, I see 2 major problems that I have trouble resolving.

1st problem: If player starts in room #1 and goes to room #2 to room #3 to room #4 and collides with the bottom door of room #4, I have to put a rule in place so the room #5 is not generated on top of room #1. Unfortunately I do not know how to check if there already exists a room below room #4.

2nd problem: If player starts in room #1 and goes to room #2 to room #3 and decides to go back to room #1 and then into room #4. The room #4 must be created as a room that has a door to the right. And again, if the player collides with a door that leads to the right but there is already a room there, it shouldn’t create a room #5.

Since there will most likely be 10 rooms created, the only idea I have right now is to make some sort of a 10x10 pseudo grid with objects named “Space”, where I will check each “Space” and its closest neighbours if they are taken, and if they are, what kind of room occupies it. But I’m not sure if that is the way to go.