Rotting Oranges | Directional Arrays & BFS | LeetCode
Vložit
- čas přidán 24. 07. 2024
- Rotting Oranges is a popular LeetCode problem asked by Amazon and Microsoft. For this problem, we are given an integer matrix containing only 0's, 1's, and 2's representing an empty cell, a fresh orange, and a rotten orange respectively. The intuition to solve this problem with BFS is that it mentions a grid as input, finding a minimum, and having very small constraints. Solving this problem with a breadth first search leads is the most optimal approach using a queue and directional arrays.
🎥 Graph Problem Tips Video: • Coding Interview Prep ...
Check out my interview prep platform for learning the patterns!
📢 Interview Prep Platform: algoswithmichael.com
🔗 Social 🔗
🎧 Join the community Discord: / discord
💰 Support me on Patreon: / michaelmuinos
🔗Follow me on LinkedIn: / michael-muinos
📂Follow me on Github: github.com/MichaelMuinos - Věda a technologie
Micheal, you are literally the most underrated creator I know now. Keep up this amazing work.
And your code quality is Kick Ass. 🔥
Haha thanks so much, I appreciate it!
Nice trick to store i,j in a single variable.Thanks for sharing.
No problem!
As always, best explanation. Best part, how to approach this kind of problem, no one talks about intuition except you. Thank you
So underrated!!!💯 Thank you for your work!
Couldn’t have been explained or visualized more effectively!
Man, that's amazing, thank you
also we can write this
for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++) {
if(grid[i][j] == 1) {
++freshOranges;
} else if(grid[i][j] == 2) {
queue.add(i * n + j);
}
}
}
Could the if-check (lines 19-21) be included in the top for loops? Just curious why we need to iterate the grid twice?
Could you please make a video on Leetcode 753. Cracking the safe. It’s a hard problem
Unable to pass all the testcases on Leetcode
Congrats for Google bro🎉🎉 . I also want to switch my current job to google . Can you help by covering the topics which google developers ask most.