O42

Rotting Oranges (Multi-Source BFS)

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

Problem Statement & Objective

You are given an m x n grid containing fresh and rotten oranges. Return the minimum number of minutes that must elapse until no cell has a fresh orange.

Function Signature (Python)

rotting_oranges_multisource_bfs(grid: list[list[int]]) -> int

Input & Output Contract

Output Rule:Minimum dakika veya -1.

System Constraints

m == izgara.length, n == izgara[i].length
1 <= m, n <= 10
izgara[i][j] ∈ {0, 1, 2}

Example Execution Walkthrough

izgara = [[2, 1, 1], [1, 1, 0], [0, 1, 1]] -> 4 dakika
izgara = [[2, 1, 1], [0, 1, 1], [1, 0, 1]] -> sol alttaki taze portakala ulaşılamaz -> -1

Example Test Scenarios (3)

Example 1
Input:[[[2,1,1],[1,1,0],[0,1,1]]]
Expected Output:4
Example 2: Ulaşılamaz
Input:[[[2,1,1],[0,1,1],[1,0,1]]]
Expected Output:-1
Example 3: Taze Yok
Input:[[[0,2]]]
Expected Output:0
Loading Python Editor...
Input Parameters
[
  [
    [
      2,
      1,
      1
    ],
    [
      1,
      1,
      0
    ],
    [
      0,
      1,
      1
    ]
  ]
]
Expected Output
4