← Questions

Rotting oranges: time for an infection to cover a grid

0
AirbnbCodingLast asked Mar 2026

A grid has empty cells, healthy cells and infected cells. Every minute each infected cell infects its healthy neighbors up, down, left and right. Return the minutes until no healthy cell is left, or -1 if some never get infected. Run a breadth-first search from all infected cells at once. Follow-up: infection also spreads diagonally.

Write and test your solution herePython in your browser, the question's tests level by level, every submission kept for you.Sign in to start coding