Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Given an integer matrix, find the length of the longest increasing path.
- From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside of the boundary (i.e. wrap-around is not allowed).
- Input format
- First line will have two space separated integers row and col denoting the size of the matrix.
- Next you will be given a matrix of integers.
- Output format
- Length of the longest increasing path.
- Sample Input 1
- 3 3
- 9 9 4
- 6 6 8
- 2 1 1
- Sample Output 1
- 4
- Explanation:
- The longest increasing path is [1, 2, 6, 9].
- Sample Input 2
- 3 3
- 3 4 5
- 3 2 6
- 2 2 1
- Sample Output 2
- 4
- Explanation:
- The longest increasing path is [3, 4, 5, 6]. Moving diagonally is not allowed.
- Constraints
- 1<= m*n <= 1000
- function longestIncreasingPathInAMatrix(n, m, grid) {
- }
- function main() {
- let nm = readIntArr();
- let n = nm[0];
- let m = nm[1];
- let grid = [];
- for (let i = 0; i < n; i++) {
- grid.push(readIntArr());
- }
- let ans = longestIncreasingPathInAMatrix(n, m, grid);
- print(ans + "\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement