Matrix - Minimum Time required to rot all oranges

Sdílet
Vložit
  • čas přidán 2. 04. 2020
  • Source Code:thecodingsimplified.com/minim...
    Solution:
    - We're representing oranges in matrix, 2 - rotten orange, 1 - fresh orange, 0 - blank
    - We implement it using queue
    - We iterate matrix & whenever we find all rotten orange (2) & put indexes in queue
    - At last we put delimeter (-1, -1)
    - Now we remove element one by one & check if it has neighboring fresh orange, then put that value in queue & mark matrix value as 2
    - We do this until queue is not empty
    - At last we check, if any fresh orange left (1) in matrix, we return as -1 else we return count
    Time Complexity: O(n * m)
    Space Complexity: O(n * m)
    Do Watch video for more info
    CHECK OUT CODING SIMPLIFIED
    / codingsimplified
    ★☆★ VIEW THE BLOG POST: ★☆★
    thecodingsimplified.com
    I started my CZcams channel, Coding Simplified, during Dec of 2015.
    Since then, I've published over 400+ videos.
    ★☆★ SUBSCRIBE TO ME ON CZcams: ★☆★
    czcams.com/users/codingsimplif...
    ★☆★ Send us mail at: ★☆★
    Email: thecodingsimplified@gmail.com

Komentáře • 13

  • @ShreyaSingh-vr9qi
    @ShreyaSingh-vr9qi Před 4 lety +2

    Nicely explained !!

  • @kushaalrana
    @kushaalrana Před 4 lety +1

    Thanks for the video awesome explanation👌

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

    super , thoughtful !!!

  • @AyushKumar-vh7pg
    @AyushKumar-vh7pg Před 4 lety +1

    Can you please make some videos on questions of graph
    Till now you have only taught DFS nad BFS but we want a few questions related to graph , please make videos on this topic, It would be really helpful.

  • @akshatjain6854
    @akshatjain6854 Před 4 lety

    why we are using flag

    • @CodingSimplified
      @CodingSimplified  Před 4 lety +1

      We want to increase count only once for one time.
      So at the starting flag is false & whenever we get 1st fresh orange, it means i've added new time, so I mark flag as true & Increase the count.
      After that I won't increase the count, that's why we've check increase count only if flag is false. Thanks.

    • @akshatjain6854
      @akshatjain6854 Před 4 lety

      @@CodingSimplified Ok sir thank you so much

  • @amolmishra8621
    @amolmishra8621 Před 3 lety +1

    Nicely explained!!