Advertisement
satishfrontenddev5

Untitled

Feb 22nd, 2024
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Given an integer matrix, find the length of the longest increasing path.
  2.  
  3. 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).
  4.  
  5. Input format
  6. First line will have two space separated integers row and col denoting the size of the matrix.
  7.  
  8. Next you will be given a matrix of integers.
  9.  
  10. Output format
  11. Length of the longest increasing path.
  12.  
  13. Sample Input 1
  14. 3 3
  15.  
  16. 9 9 4
  17.  
  18. 6 6 8
  19.  
  20. 2 1 1
  21.  
  22. Sample Output 1
  23. 4
  24.  
  25. Explanation:
  26. The longest increasing path is [1, 2, 6, 9].
  27.  
  28. Sample Input 2
  29. 3 3
  30.  
  31. 3 4 5
  32.  
  33. 3 2 6
  34.  
  35. 2 2 1
  36.  
  37. Sample Output 2
  38. 4
  39.  
  40. Explanation:
  41. The longest increasing path is [3, 4, 5, 6]. Moving diagonally is not allowed.
  42.  
  43. Constraints
  44. 1<= m*n <= 1000
  45.  
  46.  
  47. function longestIncreasingPathInAMatrix(n, m, grid) {
  48. }
  49.  
  50. function main() {
  51.     let nm = readIntArr();
  52.     let n = nm[0];
  53.     let m = nm[1];
  54.     let grid = [];
  55.     for (let i = 0; i < n; i++) {
  56.         grid.push(readIntArr());
  57.     }
  58.     let ans = longestIncreasingPathInAMatrix(n, m, grid);
  59.     print(ans + "\n");
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement