Longest Increasing Path
Practice
3.7 (23 votes)
Algorithms
Approved
Dynamic programming
Medium
Open
Two dimensional
Problem
86% Success 6328 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
There is a 2D matrix of N rows and M columns. Rows are number 1 to N from top to bottom and columns 1 to M from left to right. You are standing at (1,1).
From, A [ i ] [ j ] you can move to A [ i + 1 ] [ j ] if A [ i + 1 ] [ j ] > A [ i ] [ j ]. Or, from, A [ i ] [ j ] you can move to A [ i ] [ j + 1 ] if A [ i ] [ j + 1 ] > A [ i ] [ j ].
Moving from (1,1), what is the longest path that you can travel?
Input:
First line contains, T, the number of testcases. Each testcase consists of N, M. Each of the next N lines contain M integers each.
Output:
For each testcase, print the length of the longest path from (1,1).
Constraints:
1 ≤ T ≤ 100
1 ≤ N, M ≤ 100
1 ≤ A[i][j] ≤ 106
Submissions
Please login to view your submissions
Similar Problems
Points:30
12 votes
Tags:
AlgorithmsDynamic ProgrammingMediumPalindromesString ManipulationTwo dimensional
Points:30
14 votes
Tags:
ApprovedCombinatoricsDynamic ProgrammingMathMediumOpenTwo dimensional
Points:30
3 votes
Tags:
MediumTwo dimensional
Editorial