G-9. Flood Fill Algorithm | C++ | Java
Vložit
- čas přidán 9. 08. 2022
- GfG Problem Link: bit.ly/3bxY94d
C++/Java/Codes and Notes Link: takeuforward.org/graph/flood-...
DP Series: • Striver's Dynamic Prog...
SDE Sheet: takeuforward.org/interviews/s...
Check out our Website for curated resources:
Our Second Channel: / @striver_79
In case you are thinking to buy courses, please check below:
Code "takeuforward" for 15% off at GFG: practice.geeksforgeeks.org/co...
Code "takeuforward" for 20% off on sys-design: get.interviewready.io?_aff=takeuforward
Crypto, I use the Wazirx app: wazirx.com/invite/xexnpc4u
Take 750 rs free Amazon Stock from me: indmoney.onelink.me/RmHC/idje...
Earn 100 rs by making a Grow Account for investing: app.groww.in/v3cO/8hu879t0
Linkedin/Instagram/Telegram: linktr.ee/takeUforward
---------------------------------------------------------------------------------------------------------------------------
Let's continue the habit of commenting “understood” if you got the entire video.
Do follow me on Instagram: striver_79
After watching the above videos in this playlist, I solved this on my own🥺.
You make every difficult topic an easy one. Thank you so much😊
Good
For Java people:
int[ ][ ] ans = image; // this won't create the copy of the image array, just that ans is pointing to same as image so we are indirectly changing the original array
to make a copy run nested for loops and copy them individually and store it in ans[ ][ ]
Or just use arrays.copyOf
Use Arrays.copyOf()
It will work with the original image itself, so it will work using the ans reference also.
Can't even imagine that the topic that used to send shivers down my spine is now being solved by me, even just after watching the explanation of the problem. Thanks a lot, mate. You are a genius.
Wonderful Explanation I wrote the BFS for it myself
your graphs series is amazing, after watching all previous videos, i could solve this problem on my own , thank you so much
Understood Bhaiya!!
Bfs approach:
void bfs(int r,int c,vector& grid,vector &vis,int color,int prev)
{
int drow[4]={0,1,0,-1};
int dcol[4]={1,0,-1,0};
queue q;
q.push({r,c});
vis[r][c]=color;
while(!q.empty())
{
int p=q.front().first;
int s=q.front().second;
q.pop();
for(int i=0;i=0 && nr=0 && nc
Understood! Thank you so much for the great playlist🤩
I just understood the problem from your explanation, found it kind of similar to the no. of islands question, coded it, and bang on I wrote both bfs and dfs code correctly! This series is lit💥
Thank you for explaining the direction array concept! I always wondered why it has that structure! Thank you!
striver you are just nailing it, was able to do it without seeing the solution.
Sometimes I just stop listening and start looking at u and admire how beautifully u are explaining this ...thankyou so much
pyaar to nhi ho gya 😅😅
I was able to solve the problem with BFS and DFS just after you explained the problem. The first 3 minutes were just enough!
Understood! Great explanation as always, thank you very much!!
Great series! Solved in a go before watching the explanation.
Explained it like it is a piece of cake. Beauty is how a mammoth topic like Graph look so tiny when u enlighten us.
True Beauty is in Simplicity. Love ur videos. Thank u for sharing ur knowledge and making this a better world.
Tc. Stay safe. Keep growing.
Best graph series EVER 💚 Thank you Striver
understood!!! thank you so much for the wonderful playlist
U R SUCH AN AMAZING PERSON WITH EXCELLENT TEACHING SIR. GOD BLESS YOU.
solved it without watching the code....because you explained number of islands so beautifully! thank u bhaiya
Absolutely amazing explanation🔥🔥🔥
understood!!! har ek video me kuch na kuch naya sikhne ko mil raha h.... not only just soln but writing the code h in efficient way... will surely watch ur dp series after this!!!! waiting for the next lectures of the series
take care!
If this playlist is so good , I wonder how good will be the extremely popular dp series
Awesome intuition I solved without watching the code thank you so much striver 🙏
Great explanation striver sir :) you're our saviour!!
Understood... ! Thank you for this playlist
Your Logic Explanation is great.
understood! Wonderful explanation
understood... thanks for this amazing series :)
understood wonderful explanation... striver bhaiya makes advanced dsa interesting and easy for students like us....gem of a explanation
aap jab samjhate ho to kuch bhi samajh jaata hai......god bless you
yeah absolutely. I missed "I hope you guys are doing extremely well" makes my day😀
Liked the video, notes taken, understood
sir watched your graph series from start and solved this on my own .Thanks❤❤
Can someone explain why the TC is O(MN) + O(4MN) and not just O(4MN)? I know ultimately it's the same thing but I really want to understand the concept. Thanks Striver!
Thanks you so much Bhaiya ❣️🙏for this epic graph series
its such a good feeling when u solve the Question yourself
for num enclaves problem at leet code you can do one thing that is traversing only boundries of grid i.e top row bottom row left column and right column and if not visited ho or land ho then call bfs function like we do in this video after doing this run a for loop and Count the remaining land cells that are not visited. Thanks striver you make it very easy.
Thank You So for this wonderful video.........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
understood it very well...
understood striver
great explanation
Great explanation 👍
Thank you, Striver 🙂
The command you have over graph problems is 🔥🔥
Best explanation 💥
Thanks for amazing explanation
understood, thanks!
Understood Striver, Thankyou!
UNDERSTOOD!!!
understood very good
thank you so much. God Bless Us
understood , op explaination
Understood Striver, thanks a lot
Thank you so much bro!!!!
Understood 🙌
Understood🌻
best explanation☺
I love ur opening line
Understood sir !
understood well
understood striver
Understood ❤
Isn't the recursion space stack will be O(max(m,n))?? Because as we need to cover up all the elements ranging in n*m pixel table the maximum we can go is the maximum of given rows and given columns.
Understood!
Thank you sir
Understood 😊
Thank you bhaiya
defining the dfs/bfs function as private is just a good code practice or does it have some other reason?
understood💙💙💙
understood !!
Understood sirji
why does it show compilation error if instead of copying the image matrix to a new matrix,I modify the image matrix itself and return it?
One man teaching entire India the best for free 🙂🙂🙂
Understood sir🙇♂❤🙏
Understood💯💯
understood!
was able to do the bfs on my own
:)
Is it copying image array into ans array or is it just passing the reference to it and it will end up changing the image array anyway? Talking about java code
understood
after watching the rotten oranges i solved this question by myself using bfs and its time to learn using dfs thank you so much for the clear explanation
can you share the bfs code? i wrote bs code and it gave me TLE
try to check if you addded the condition of checking whether the node is visited or not@@taneyasoni
thank you@@shrujaigupta2586
@striver as always another great video however taking ans as separate reference to original 2d array seems unnecessary and the explanation for the check ans[nrow][ncol] != newColor is not satisfactory since ans and image are the reference to same array, i think this explanation should be that initial color and new color can be the same so it might result in stack overflow unless we make this check
it gave me stack overflow error until i added a visited array.
thanks bro been searching this for 1/2 hour thanx
Take love from Bangladesh
Understood bhaiya
thanks
Understood!
Understood:)
I always solve the question just after watching 5 minutes of every video, & this works well.
Try to solve questions like me & thanks me later
Thanks. Understood
Bro Time Complexity wala part thoda explain kar skte ho?? Smjh nhi aaya mujhe
solved it by myself just watching the privious island video....two or three problem on leetcode can be solve by using the logic of island
understood.
understood sir
solved on my own before watching the video using dfs🙂
Here is both dfs and bfs approach:
class Solution {
private:
void dfs(vector&image,vector&img,int sr,int sc,int iniColor,int newColor)
{
img[sr][sc] = newColor;
int delrow[] = {-1,0,1,0};
int delcol[] = {0,1,0,-1};
for(int i=0;i
first time i solved a question on my own 🥺
awesome
understood :)
Got tle in the same question at code studio. Any optimisation in same code?
Understood.
Thank you so much
Understood
BESTTT BESST TEACHHERRR
understooodddddd