Grokking Data Structures & Algorithms for Coding Interviews
Vote

0% completed

Solution: Rotting Oranges

Problem Statement

Given a grid of empty cells, fresh oranges and rotten oranges, where rot spreads one step each minute to the four side neighbours, return the number of minutes until no fresh orange is left, or -1 if that never happens.

Examples

Example 1

  • Input: grid = [[2,1,1],[1,1,0],[0,1,1]]
  • Expected Output: 4

Example 2

  • Input: grid = [[2,1,1],[0,1,1],[1,0,1]]
  • Expected Output: -1

Example 3

  • Input: grid = [[0,2]]
  • Expected Output: 0

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content