FastPrepMinimum Time to Spread Through a Grid
Problems/Minimum Time to Spread Through a Grid

Minimum Time to Spread Through a Grid

Amazon logoAmazon● MediumFULLTIMENEW GRADPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon onsite interview for full-time and new grad roles. The report named the basic problem of spreading across a grid, and a search that starts from many cells at once. It left out the variation and the number limits, and we do not guess at them. Our version is about 95% the same as the part of the task that was kept.

You are given a rectangular grid whose cells contain 0, 1, or 2. A zero is empty, a one is fresh, and a two is already active.

After each minute, every active cell makes each orthogonally adjacent fresh cell active. Return the minimum number of minutes until no fresh cell remains. Return -1 when this is impossible.

Function

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

Examples

Example 1

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

The wave reaches the lower-right fresh cell after four minutes.

Example 2

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

The isolated fresh cell in the lower-left corner is unreachable.

Example 3

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

There are no fresh cells, so no minute needs to pass.

Constraints

  • 1 <= grid.length, grid[r].length <= 200
  • Every row has the same length.
  • grid[r][c] is 0, 1, or 2.

Source note: Source images are source-neutral excerpts of author-reported interview prompts.

More Amazon Onsite Interview questions

  • Assign Escalations to TeamsONSITE INTERVIEW · Seen Nov 2026
  • Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximum Earnings Across WarehousesONSITE INTERVIEW · Seen Nov 2026
  • Priority Message BufferONSITE INTERVIEW · Seen Nov 2026
  • Search in a Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Maximal SquareONSITE INTERVIEW · Seen Nov 2026
  • Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Number of IslandsFleetx · ONSITE INTERVIEW
  • Matrix EscapeByteDance · PHONE SCREENByteDance interview questions
  • Number of IslandsIntuit · ONSITE INTERVIEWIntuit interview questions
  • Rotting OrangesSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Max Area of Island Without Changing the GridFlexport · PHONE SCREENFlexport interview questions
  • Minimum Time to Rot All OrangesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Reachable Exits in an Obstacle GridWhatNot · PHONE SCREENWhatNot interview questions
  • Number of Islands with Diagonal ConnectivityGoogle · ONSITE INTERVIEWGoogle interview questions
  • Island Count and Maximum AreaOracle · ONSITE INTERVIEWOracle interview questions
  • Shortest Increasing Path to a TargetUber · ONSITE INTERVIEWUber interview questions

Interview reports that mention this question

  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
  • Amazon Frontend Spring 2025 Loops: 11 Experiences (Part 2 of 2)
  • Amazon Frontend Engineer Interviews: 21 Experiences (Part 1 of 2)

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
See Amazon hiring insights
Saved
class Solution {
    public int minutesToSpread(int[][] grid) {
        // Write your solution here.
    }
}
Checking account…