


3 2 2
5 6 6
9 5 11
In the given matrix, 3 → 5 → 6 and 3 → 5 → 9 form increasing paths of length 3 each.
The first line of input contains an integer 'T' representing the number of test cases or queries to be processed. Then the test case follows.
The first line of each test case contains two space-separated integers 'N', 'M' where 'N' and 'M' denote the number of rows and columns of the matrix, respectively.
From the second line of each test case, the next 'N' lines represent the rows of the MATRIX. Every row contains 'M' single space-separated integers.
For each test case, print the length of the longest increasing path.
Print the output of each test case in a separate line.
Note :
You do not need to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 100
1 <= N <= 50
1 <= M <= 50
0 <= MATRIX[i] <= 10^5
Time Limit: 1sec
The idea is to use DFS to find the length of the increasing path for every element.
We traverse the matrix and find the length of the longest increasing path starting from each cell.
In the previous approach, the longest path starting from each cell is calculated again every time that cell is revisited. So, the idea is to use DFS with memoization to improve time complexity.
We maintain a 2D array dp of size N*M. Since the increasing path can start from any point in the matrix, we use dp[i][j] to store the length of the longest increasing path starting from location (i, j). This ensures that we do not recalculate a visited location.