FastPrepRotten Oranges / Grid Infection BFS
Problems/Rotten Oranges / Grid Infection BFS

Rotten Oranges / Grid Infection BFS

Lyft logoLyft● MediumFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given a two-dimensional grid representing cells in an infection simulation. Each cell has one of three values:

  • 0: empty
  • 1: fresh
  • 2: infected

Each minute, every currently infected cell simultaneously infects its 4-directional fresh neighbors. Fresh cells infected during the current minute can only infect other cells in later minutes.

Return the minimum number of minutes needed until there are no fresh cells left. If some fresh cell can never be infected, return -1. If there are no fresh cells at the start, return 0.

Function

minimumMinutesToInfectAll(grid: int[][]) → int

Examples

Example 1

grid = [[2, 1, 1], [1, 1, 0], [0, 1, 1]]return = 4
grid
012021111102011

The infection spreads level by level from the initial infected cell. The last fresh cell is infected after 4 minutes.

Example 2

grid = [[2, 1, 1], [0, 1, 1], [1, 0, 1]]return = -1
grid
012021110112101

The fresh cell in the lower-left corner is isolated by empty cells, so it can never be infected.

Example 3

grid = [[0, 2]]return = 0
grid
01002

There are no fresh cells at the start.

Constraints

  • grid is a rectangular matrix.
  • Each cell is 0, 1, or 2.
  • Infection spreads only in the four orthogonal directions.

More Lyft interview questions

  • Keyboard Autocomplete SuggestionsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Window SubstringPHONE SCREEN · Seen Oct 2026
  • Deterministic K-Means AssignmentsPHONE SCREEN · Seen Oct 2026
  • Nested Transaction Key-Value Store with Value CountsONSITE INTERVIEW · Seen Sep 2026
  • Stateful Paginated Fetch NPHONE SCREEN · Seen Sep 2026
  • Globally Versioned Key-Value StoreONSITE INTERVIEW · Seen Sep 2026
  • Reconstruct a BST from PreorderPHONE SCREEN · Seen Aug 2026
  • Validate Binary Search TreePHONE SCREEN · Seen Aug 2026
  • Minimum Workers with Job AssignmentsONSITE INTERVIEW · Seen Jul 2026

Similar questions at other companies

  • Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions
  • Simulate Orchard Rot SpreadAirbnb · OAAirbnb interview questions
  • Simulate Orchard Rot SpreadCapital One · OACapital One interview questions
  • Shortest Path in a Binary MatrixGoogle · OAGoogle interview questions
  • Minimum MovesHarness · OA
  • Shortest Atom Action PathOpenAI · OAOpenAI interview questions
  • Minimum Cleaning Robot RunsHSBC · OAHSBC interview questions
  • Shortest Path Around Rectangular ObstaclesDRW · OADRW interview questions
  • Count Islands with DFS and BFSVisa · OAVisa interview questions
  • Closest DashMartDoorDash · OA · PHONE SCREENDoorDash interview questions

Lyft interview experiences

  • Lyft MLE Intern Statistics Phone Screen: 1 Experience
All Lyft interview questionsSee Lyft hiring insights
Saved
class Solution {
    public int minimumMinutesToInfectAll(int[][] grid) {
      // write your code here
    }
}
Checking account…