Given a matrix where every element is either ‘O’ or ‘X’, find the largest subsquare surrounded by ‘X’.

**Input:**

First line contains number of test cases T. For each test case, first line contains the integer value 'N' denoting the order of square matrix. Last line contains NxN elements in a single line in row-major order.

**Output:**

Print the size of largest subsquare surrounded by ‘X’.

**Constraints:**

1<=T<=50

1<=N<=10

**Example:**

Input:

2

2

X X X X

4

X X X O X O X X X X X O X O X X

Output:

2

3

**Explaination:**

In first example above, input represents following matrix of size 2 x 2

X X

X X

The largest square submatrix surrounded by X is the whole input matrix.

In second example above, input represents following matrix of size 4 x 4

X X X O

X O X X

X X X O

X O X X

The square submatrix starting at (0,0) and end at (2,2) is the largest submatrix surrounded by ‘X’.

Therefore, size of that matrix would be 3.

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

thanuvinu94 | 425 |

the_coder95 | 380 |

RishabhTanwar1 | 280 |

shubham3174 | 208 |

RitikRosan | 202 |

the_coder95 | 1226 |

RishabhTanwar1 | 1000 |

thanuvinu94 | 634 |

tathagat289 | 628 |

themanhasnoname | 620 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4885 |

Quandray | 4547 |

Login to report an issue on this page.