⌘K
Flycodx

Amazon Warehouse Rotten Oranges BFS

Amazon Warehouse Rotten Oranges BFS

MediumGraphs100% accepted

Amazon warehouse grid: 0=empty, 1=fresh orange, 2=rotten orange. Every minute rotten oranges infect adjacent fresh ones. Find the minimum minutes until no fresh orange remains, or -1 if impossible.

Approach

Multi-source BFS: minimum time for rotten oranges to infect all fresh ones.

Input

3 3 2 1 1 1 1 0 0 1 1

Output

4
solution.py
Loading editor...
Test 1
Test 2
Test 3

Press Run to test your custom input, or Submit to judge against all test cases.

Sign in to continue

Create a free account to run code, submit solutions and track progress.

  • Free forever — no credit card
  • 10+ languages with live execution
  • Points, streaks & leaderboards
Auto Save OnLn 1, Col 1Spaces: 4UTF-8LFPython 3