Micro and Matrix
Practice
4.6 (7 votes)
Algorithms
Approved
Dynamic programming
Medium
Two dimensional
Problem
76% Success 2553 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

In Micro's class, students sit in a matrix of N rows and N columns, both numbered from 1 to N. Each student is having an I.Q. level, which is an integer value. It's history class right now and Micro is getting really bored. So, he started wondering about an interesting problem. He wants to find out the largest number X, such that there is a submatrix of size \(X \times X\) in which all students have same I.Q. level. Please help Micro to find out the answer.

Input:
First line consists of a single integer T denoting the number of test cases.
First line of each test case consists of a single integer denoting N.
Each of the following N lines consists of N space separated integers. \(j^{th}\) integer in \(i^{th}\) row denotes the I.Q. level of the student sitting on \(j^{th}\) chair of \(i^{th}\) row.

Output:
For each test case print the largest possible value of X in a new line.

Constraints:
\(1 \le T \le 10 \)
\(1 \le N \le 1000\)
\(1 \le A[i][j] \le 10^9, A[i][j] = \) I.Q. level of the student sitting on \(j^{th}\) chair of \(i^{th}\) row.

Note: Please use fast I/O methods.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
24 votes
Tags:
AlgorithmsDynamic ProgrammingDynamic programming
Points:30
20 votes
Tags:
Dynamic ProgrammingMediumReady
Points:30
13 votes
Tags:
2-D ArrayAlgorithmsApprovedDynamic ProgrammingDynamic programmingMedium