Breadth-First Search pattern
Rotting Oranges
Given a grid whose cells are empty, hold a fresh orange, or hold a rotten orange, each minute every fresh orange adjacent to a rotten one becomes rotten; return the minimum number of minutes until no fresh orange remains, or -1 if some fresh orange can never rot. Watch it run step by step, then write your own pseudocode and get it checked by AI.
- LeetCode 994
- Medium
- 1 approach
Sign in with Google or GitHub and you land straight on this page. DSA comes with the all labs plan and every ChaiCode batch.
Breadth-First SearchLeetCode 994
Medium
The approach
- 01 Multi-source BFS by minute O(R·C)O(R·C) space
What you will learn
- How to read Rotting Oranges and spot the breadth-first search pattern in it
- Multi-source BFS by minute: O(R·C) time, O(R·C) space
- The pseudocode for each approach, its line lit as the animation runs
- Practice: write your own pseudocode and get it checked
More Breadth-First Search
See Rotting Oranges run, step by step
Sign in and this page opens on the animation, with all 8 Breadth-First Search problems beside it.
DSA comes with the all labs plan and every ChaiCode batch.