If you have one brick on the edge of a table, it will fall if its center of mass is not above the table. If more than half of the brick is above the table, the force of gravity will produce a torque around the axis along the edge of the table that will keep the brick pressed against the table. If less than half of the brick is on the table, the center of mass isn't above the table, and the force of gravity will produce a torque that will make the brick fall of the table.
If the center of mass is exactly above the edge of the table, the torque will be 0.
The same goes for a brick that is on top of another brick. And it also goes for a stack of N bricks on top of another brick. The critical value for falling/not falling is when the center of mass of the N bricks is exactly above the edge of the brick below it.
This goes for the top brick of a stack, for the 2 top bricks, etc.
suppose the x coordinates of the middle of the bricks of a stack of N bricks are x_1 ... x_N (x_1 is the top brick). suppose the length of a brick is 1.
since the top brick must not fall its center of mass at x_1 can be at most x_2 + 1/2. The critical value occurs for x_1 = x_2 + 1/2
since the top 2 bricks must not fall their center of mass (x_1 + x_2)/2 can be at most x_3+1/2 etc. this must be true for each substack at the bottom of the complete stack.
You can think of the table as brick N+1 at position x_(N+1) = 0. The big question is, how big can x_1 get?
This is mainly a math problem