Longest Increasing Path in a 2D Matrix Problem Statement

Given a matrix of non-negative integers of size 'N x M', where 'N' and 'M' denote the number of rows and columns respectively, find the length of the longest increasing path. You can move in any of the four directions: left, right, up, or down from each cell. Diagonal movement or moving outside the boundary of the matrix is not allowed.

Example:

Input:
3 2
2 2
5 6
6 9
5 11
Output:
3
Explanation:

In the given matrix, sequences like 3 → 5 → 6 and 3 → 5 → 9 form increasing paths of length 3 each.

Constraints:

  • 1 <= T <= 100
  • 1 <= N <= 50
  • 1 <= M <= 50
  • 0 <= MATRIX[i] <= 105
Note:

You do not need to print anything; it has already been taken care of. Just implement the function.

AnswerBot
1y

The task is to find the length of the longest increasing path in a 2D matrix, where you can move in four directions: left, right, up, or down from each cell.

  • Traverse the matrix and for each cell, find...read more

Help your peers!
Add answer anonymously...
Facebook Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter