Rotting Oranges
A medium-tier problem at 57% community acceptance, tagged with Array, Breadth-First Search, Matrix. Reported in interviews at DP world and 33 others.
Rotting Oranges hits your OA and you blank on the state transitions. You've got a grid. Some oranges rot each minute. Fresh oranges adjacent to rotten ones become rotten. You need the minimum time to rot them all, or return -1 if it's impossible. The trick isn't simulation. It's BFS from multiple starting points at once. PayPal, Lyft, Intuit, and eight other major companies ask this. The acceptance rate sits at 57%, which means a quarter of candidates mess up the multi-source BFS pattern or forget the edge case where fresh oranges can't be reached. StealthCoder surfaces the clean solution in seconds if you hit the wall during your assessment.
Companies that ask "Rotting Oranges"
Rotting Oranges is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by a senior engineer who knows the OA is theater. This is the script.
Get StealthCoderThe naive approach is to simulate minute by minute, checking every cell each time. That works but feels slow and error-prone. The insight is that this is a shortest-path problem in disguise. All rotten oranges start rotting simultaneously at minute 0. You queue them all at once, then BFS outward. Each orange you dequeue and process represents one minute of spread. The real pitfalls are forgetting to initialize the queue with all starting rotten oranges, miscounting the distance, or returning the wrong answer when a fresh orange is unreachable. You also need to validate that every fresh orange got visited. If one didn't, return -1. Array, Matrix, and Breadth-First Search are the three topics here, and BFS is non-negotiable. If you blank on the multi-source queue setup during the live OA, StealthCoder runs invisibly and hands you the working code before you lose momentum.
Pattern tags
You know the problem.
Make sure you actually pass it.
Rotting Oranges recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Rotting Oranges interview FAQ
Why is BFS the right approach here?+
All rotten oranges spread simultaneously, like a level-order traversal. BFS naturally handles level-by-level expansion. Each layer in the BFS represents one minute. DFS won't give you the shortest time because it explores depth-first, not breadth-first. Multi-source BFS is the standard pattern for problems where multiple starting points spread outward at the same rate.
Is this really asked at Lyft and PayPal?+
Yes. DP World, Lyft, PayPal, Intuit, Wix, and 29 other companies have reported asking this. The 57% acceptance rate suggests it's harder in practice than on the surface. Most fails are logic errors in the BFS setup or the final validation step, not conceptual confusion.
What's the edge case that trips people up?+
Not checking that all fresh oranges got visited. If even one fresh orange is surrounded by walls and unreachable, you must return -1. Candidates often miss this and return the max time anyway. Also, if there are no fresh oranges to begin with, return 0 immediately, not the result of an empty BFS.
Do I need to modify the input grid or use extra space?+
Using a visited set is cleaner than modifying the grid in place, though both work. Most production code avoids mutating inputs. You'll also need the queue for BFS and a way to track the maximum time reached. Plan for O(rows * cols) space in the worst case. It's not a constraint trap, just be aware.
How does this relate to the Matrix and Array topics?+
The grid is a 2D array (matrix). You navigate it by row and column offsets. You'll iterate over neighbors (up, down, left, right), so directional vectors are standard. The problem combines basic array iteration with graph traversal. It's not matrix math or linear algebra, just spatial reasoning.
Want the actual problem statement? View "Rotting Oranges" on LeetCode →