How to find Maximum perimeter of rectangle in a grid with obstacles? (Dynamic Programming)
Your approach is basically correct. However, be sure to pay attention to a few boundary cases besides the general cases for x2>x1 and y2>y1.


Initialize the tables on a single square, i.e., dp[x][y][x][y] = (board[x][y] == 0);
Compute the case when the table can be on a single column, dp[x1][y][x2][y] = dp[x1][y][x2-1][y] &amp;&amp; (board[x2][y] == 0), where x2>x1.
Compute the case when the table can be on a single row, dp[x][y1][x][y2] = dp[x][y1][x][y2-1] &amp;&amp; (board[x][y2] == 0), where y2>y1.


For brevity, those boundary cases are not mentioned explicitly in the editorial. Once those cases are included, the algorithm will be fully correct.