LeetCode 994: Rotting Oranges | JavaScript BFS Solution Explained
Crappy Coder
0:00 / 0:00
LeetCode 994: Rotting Oranges | JavaScript BFS Solution Explained
160 просмотров · 1 г. назад
Crappy Coder
44 подписчика
160 просмотров · 1 г. назад
In this video, we solve LeetCode 994 - Rotting Oranges in JavaScript using a Breadth-First Search (BFS) approach. This popular interview problem asks you to determine the minimum time needed for all fresh oranges in a grid to become rotten, spreading from adjacent rotten oranges each minute.
We’ll simulate the rotting process using BFS, starting from all initially rotten oranges at once. By processing each layer in the BFS queue, we can efficiently track the number of minutes it takes for all fresh oranges to rot — or determine if it’s impossible.
📌 What you’ll learn in this video:
How BFS works for multi-source spread problems
How to track fresh oranges and stop early when done
How to handle cases where rotting is impossible
Time and space complexity analysis
📊 Complexity Analysis:
Time Complexity: O(m × n) — Each cell is processed at most once.
Space Complexity: O(m × n) — For the BFS queue.
✅ Perfect for:
Coding interview preparation
Practicing BFS and grid traversal
Understanding multi-source BFS in grid problems
🟩 Timestamps:
0:00 - Problem Statement
2:10 - BFS Concept Overview
10:05 - Code Walkthrough
16:25 - Time & Space Complexity