O48

Shortest Path in Binary Matrix

Mid / Senior Engineer
Target Time: 25 - 35 Minutes
Type: NUMERIC

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]]) -> int

Input & 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: 4

Example Test Scenarios (3)

Example 1: Çapraz Geçiş
Input:[[[0,1],[1,0]]]
Expected Output:2
Example 2
Input:[[[0,0,0],[1,1,0],[1,1,0]]]
Expected Output:4
Example 3: Başlangıç Engelli
Input:[[[1,0,0],[1,1,0],[1,1,0]]]
Expected Output:-1
Loading Python Editor...
Input Parameters
[
  [
    [
      0,
      1
    ],
    [
      1,
      0
    ]
  ]
]
Expected Output
2