Daily Coding Challenge
Solve today's challenge, earn streaks, and climb the leaderboard!
Longest Increasing Matrix Path
Given an integer matrix, find the length of the longest increasing path. You can move in four cardinal directions: up, down, left, or right.
Problem Statement
You are given an `m x n` integer matrix. Your task is to find the length of the longest strictly increasing path in the matrix. An increasing path means that each subsequent cell in the path must have a value strictly greater than the current cell. You are allowed to move horizontally or vertically (up, down, left, right), but not diagonally. You cannot move outside the matrix boundaries. The solution function `solution(matrix)` should return a single integer representing the maximum path length. Consider edge cases such as matrices where no increasing path beyond a single cell exists, or matrices with a single element. Constraints: `1 <= m, n <= 200`. Each `matrix[i][j]` will be an integer between `0` and `10^5`.
Example Test Cases
matrix = [[9,9,4],[6,6,8],[2,1,1]]
"4"
The longest increasing path is 1 -> 2 -> 6 -> 8 (or 1 -> 2 -> 6 -> 9), which has a length of 4.
matrix = [[3,4,5],[3,2,6],[2,2,1]]
"4"
The longest increasing path is 3 -> 4 -> 5 -> 6, with a length of 4.
matrix = [[10,1,9],[2,8,3],[7,4,6]]
"3"
Paths like 1 -> 2 -> 7 or 8 -> 9 -> 10 have a length of 3.
Sign in to save your progress and compete on the leaderboard
Leaderboard
Longest Increasing Matrix Path
No submissions yet for this filter
Be the first to solve this challenge!