Rotting Oranges | Directional Arrays & BFS | LeetCode

Sdílet
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

Komentáře • 13

  • @iameenr
    @iameenr Před 2 lety +3

    Micheal, you are literally the most underrated creator I know now. Keep up this amazing work.
    And your code quality is Kick Ass. 🔥

  • @micosair
    @micosair Před 2 lety +5

    Nice trick to store i,j in a single variable.Thanks for sharing.

  • @vivek.tiwary
    @vivek.tiwary Před 2 lety

    As always, best explanation. Best part, how to approach this kind of problem, no one talks about intuition except you. Thank you

  • @yunyixu5994
    @yunyixu5994 Před 5 měsíci

    So underrated!!!💯 Thank you for your work!

  • @TheElementFive
    @TheElementFive Před 2 lety

    Couldn’t have been explained or visualized more effectively!

  • @odrare
    @odrare Před 6 měsíci

    Man, that's amazing, thank you

    • @odrare
      @odrare Před 6 měsíci

      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);
      }
      }
      }

  • @yaboyspence
    @yaboyspence Před 2 lety +1

    Could the if-check (lines 19-21) be included in the top for loops? Just curious why we need to iterate the grid twice?

  • @kavyak.p8878
    @kavyak.p8878 Před 2 lety

    Could you please make a video on Leetcode 753. Cracking the safe. It’s a hard problem

  • @dvfrost6227
    @dvfrost6227 Před 3 měsíci

    Unable to pass all the testcases on Leetcode

  • @prithvirajrathore4256
    @prithvirajrathore4256 Před 2 lety

    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.