Matrix - Minimum Time required to rot all oranges
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
Nicely explained !!
Thanks
Thanks for the video awesome explanation👌
Thanks. Keep Watching.
super , thoughtful !!!
Thanks for your nice feedback. Keep Watching.
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.
Sure, I'll do it soon.
why we are using flag
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.
@@CodingSimplified Ok sir thank you so much
Nicely explained!!
Thanks for your nice feedback. Keep Watching.