O48
Shortest Path in Binary Matrix
Problem Statement & Objective
Given an n x n binary matrix grid, return the length of the shortest clear path from top-left to bottom-right.
Function Signature (Python)
shortest_path_in_binary_matrix(grid: list[list[int]]) -> intInput & Output Contract
Output Rule:En kısa yol hücre sayısı veya -1.
System Constraints
n == izgara.length == izgara[i].length
1 <= n <= 100
izgara[i][j] ∈ {0, 1}Example Execution Walkthrough
izgara = [[0, 1], [1, 0]] -> (0,0) -> (1,1) çapraz 2 adım -> cevap: 2
izgara = [[0, 0, 0], [1, 1, 0], [1, 1, 0]] -> cevap: 4Example Test Scenarios (3)
Example 1: Çapraz Geçiş
Input:
[[[0,1],[1,0]]]Expected Output:
2Example 2
Input:
[[[0,0,0],[1,1,0],[1,1,0]]]Expected Output:
4Example 3: Başlangıç Engelli
Input:
[[[1,0,0],[1,1,0],[1,1,0]]]Expected Output:
-1