Grokking Data Structures & Algorithms for Coding Interviews
Vote

0% completed

Stretch Problem: Rotting Oranges (medium)

This problem is optional. The problems above cover what the chapter teaches. This one is here for readers who want a harder queue question, and nothing later in the course depends on it.

Problem Statement

You are given a grid where each cell holds one of three values:

  • 0 is an empty cell,
  • 1 is a fresh orange,
  • 2 is a rotten orange.

Every minute, a fresh orange that shares a side with a rotten orange becomes rotten. Sharing a side means directly above, below, left or right, never diagonally.

Return the number of minutes until no fresh orange is left

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content