569. Shortest Path with Constraints
0
Easy
Given a square matrix of positive integers with dimensions N x N, determine the length of the shortest path from the top-left cell to the bottom-right cell, while adhering to the given constraints.
Input Format
An integer N representing the number of rows and columns in the matrix.
N x N elements of the matrix.
N x N elements of the matrix.
Output Format
An integer representing the length of the shortest path.
Example
Input
10
7 1 3 5 3 6 1 1 7 5
2 3 6 1 1 6 6 6 1 2
6 1 7 2 1 4 7 6 6 2
6 6 7 1 3 3 5 1 3 4
5 5 6 1 5 4 6 1 7 4
3 5 5 2 7 5 3 4 3 6
4 1 4 3 6 4 5 3 2 6
4 4 1 7 4 3 3 1 4 2
4 4 5 1 5 2 3 5 3 5
3 6 3 5 2 2 6 4 2 1
Output
6
Constraints
0<=N<=50
0<=mat[i][j]<=N
0<=mat[i][j]<=N
Loading...
View Submissions
Console