I think it can be solved using DP.

Have two DP Arrays, one for Columns, and one for Rows.

ie. dpRows[i,j] = number of X's that can be burst in the current row,

and dpCols[i, j] = number of X's that can be burst in the current column.

You need two n^2 iterations, one from Top left to bottom right, and one from bottom right to top left, updating both dpRows and dpColums.

Whenever you encounter 'Y', a wall, dpRows[i, j] becomes 0;

The result will be the maximum of dpRows[i,j] + dpCols[i,j] at the end.

The below code should be done from TopLeft to BottomRight

```
if(array[i][j] == 'X') {
dpRows[i][j] = dpRows[i-1][j] + 1;
dpCols[i][j] = dpCols[i][j-1] + 1;
}else if(array[i][j] == '0'){
dpRows[i][j] = dpRows[i-1][j];
dpCols[i][j] = dpCols[i][j-1];
}else {
dpRows[i][j] = 0;
dpCols[i][j] = 0;
}
```

Do the same from BottomRight to TopLeft

```
if(array[i][j] == 'X') {
dpRows[i][j] += dpRows[i+1][j] + 1;
dpCols[i][j] += dpCols[i][j+1] + 1;
}else if(array[i][j] == '0'){
dpRows[i][j] += dpRows[i+1][j];
dpCols[i][j] += dpCols[i][j+1];
}else {
dpRows[i][j] = 0;
dpCols[i][j] = 0;
}
```

**EDIT :** i think it should be an update like this, when you're doing bottomright to top left

`dpRows[i][j] +=`

because the previous values are updated. So I updated the above accordingly.

Please let me know if you think this works.