Rotting Oranges
Updated
Problem statement
You are given an m x n grid where 0 is an empty cell, 1 is a fresh orange, and 2 is a rotten orange. Every minute, each fresh orange that is orthogonally adjacent to a rotten orange becomes rotten.
Return the minimum number of minutes until no fresh orange remains. Return -1 if this is impossible.
Function
orangesRotting(grid: int[][]) → intExamples
Example 1
grid = [[2,1,1],[1,1,0],[0,1,1]]return = 4A breadth-first spread from the initial rotten orange reaches the last fresh orange after four minutes.
Example 2
grid = [[2,1,1],[0,1,1],[1,0,1]]return = -1The fresh orange in the lower-left corner cannot be reached through orthogonal neighbors.
Example 3
grid = [[0,2]]return = 0No fresh orange is present, so zero minutes are needed.
Constraints
1 <= m, n <= 10grid[i][j]is0,1, or2.- Adjacency is orthogonal: up, down, left, or right.
More Bloomberg LP Phone Screen questions
- Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
- Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Matrix EscapeByteDance · PHONE SCREENByteDance interview questions
- Minimum Time to Spread Through a GridAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Max Area of Island Without Changing the GridFlexport · PHONE SCREENFlexport interview questions
- Reachable Exits in an Obstacle GridWhatNot · PHONE SCREENWhatNot interview questions
- Process Minesweeper Game OperationsAmperity · PHONE SCREENAmperity interview questions
- Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
- Find and Reconstruct a Binary-Matrix PathMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Pacific Atlantic Water FlowAnduril · PHONE SCREENAnduril interview questions
- House Bounds in a Ragged GridRippling · OA · PHONE SCREENRippling interview questions
- Nearest Reachable Grid CornerSplunk · PHONE SCREENSplunk interview questions
Interview reports that mention this question
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
- Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)