G-9. Flood Fill Algorithm | C++ | Java

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

Komentáře • 299

  • @takeUforward
    @takeUforward  Před 2 lety +53

    Let's continue the habit of commenting “understood” if you got the entire video.
    Do follow me on Instagram: striver_79

  • @tejashwinibadi9984
    @tejashwinibadi9984 Před 2 lety +108

    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😊

  • @RahulGuptaa29
    @RahulGuptaa29 Před rokem +30

    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[ ][ ]

  • @anirvangoswami
    @anirvangoswami Před rokem +29

    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.

  • @aryanshaw4447
    @aryanshaw4447 Před rokem +25

    Wonderful Explanation I wrote the BFS for it myself

  • @anikethdeshpande8336
    @anikethdeshpande8336 Před rokem +10

    your graphs series is amazing, after watching all previous videos, i could solve this problem on my own , thank you so much

  • @mriduljain6809
    @mriduljain6809 Před rokem +5

    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

  • @ishwaripednekar5164
    @ishwaripednekar5164 Před rokem +2

    Understood! Thank you so much for the great playlist🤩

  • @arkajyotinaskar2858
    @arkajyotinaskar2858 Před rokem +5

    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💥

  • @yevengyklaus7066
    @yevengyklaus7066 Před rokem

    Thank you for explaining the direction array concept! I always wondered why it has that structure! Thank you!

  • @becSaurabhKumarSingh
    @becSaurabhKumarSingh Před rokem +1

    striver you are just nailing it, was able to do it without seeing the solution.

  • @manyagautamrajput9796
    @manyagautamrajput9796 Před rokem +7

    Sometimes I just stop listening and start looking at u and admire how beautifully u are explaining this ...thankyou so much

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

    I was able to solve the problem with BFS and DFS just after you explained the problem. The first 3 minutes were just enough!

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

    Understood! Great explanation as always, thank you very much!!

  • @raghavagrawal9240
    @raghavagrawal9240 Před rokem

    Great series! Solved in a go before watching the explanation.

  • @eklavya22k34
    @eklavya22k34 Před 10 měsíci

    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.

  • @user-ny1kv3xh4w
    @user-ny1kv3xh4w Před rokem

    Best graph series EVER 💚 Thank you Striver

  • @suheabkhan2546
    @suheabkhan2546 Před 2 lety

    understood!!! thank you so much for the wonderful playlist

  • @preetkatiyar969
    @preetkatiyar969 Před rokem +2

    U R SUCH AN AMAZING PERSON WITH EXCELLENT TEACHING SIR. GOD BLESS YOU.

  • @neelx9437
    @neelx9437 Před rokem

    solved it without watching the code....because you explained number of islands so beautifully! thank u bhaiya

  • @rupamrai9455
    @rupamrai9455 Před rokem +1

    Absolutely amazing explanation🔥🔥🔥

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

    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!

    • @sumerrawat6947
      @sumerrawat6947 Před rokem +6

      If this playlist is so good , I wonder how good will be the extremely popular dp series

  • @shaikrahaman8933
    @shaikrahaman8933 Před rokem

    Awesome intuition I solved without watching the code thank you so much striver 🙏

  • @devenvedi128
    @devenvedi128 Před rokem

    Great explanation striver sir :) you're our saviour!!

  • @iDepth
    @iDepth Před 2 lety

    Understood... ! Thank you for this playlist

  • @VIVEKKUMAR-km7tw
    @VIVEKKUMAR-km7tw Před 6 měsíci

    Your Logic Explanation is great.

  • @komalkrishna7836
    @komalkrishna7836 Před rokem

    understood! Wonderful explanation

  • @user-el6hv6em7m
    @user-el6hv6em7m Před 17 dny

    understood... thanks for this amazing series :)

  • @TravelTracksByDebo
    @TravelTracksByDebo Před 2 lety

    understood wonderful explanation... striver bhaiya makes advanced dsa interesting and easy for students like us....gem of a explanation

  • @shashankpratapwar-wj7xl
    @shashankpratapwar-wj7xl Před 4 měsíci

    aap jab samjhate ho to kuch bhi samajh jaata hai......god bless you

  • @rishika6525
    @rishika6525 Před rokem

    yeah absolutely. I missed "I hope you guys are doing extremely well" makes my day😀

  • @ramanpareek5218
    @ramanpareek5218 Před 24 dny

    Liked the video, notes taken, understood

  • @photon7166
    @photon7166 Před rokem +6

    sir watched your graph series from start and solved this on my own .Thanks❤❤

  • @__ngl__
    @__ngl__ Před měsícem +2

    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!

  • @Alokkkk18
    @Alokkkk18 Před 2 lety

    Thanks you so much Bhaiya ❣️🙏for this epic graph series

  • @enigmanarratives1
    @enigmanarratives1 Před rokem

    its such a good feeling when u solve the Question yourself

  • @sachin_singh_tomar_
    @sachin_singh_tomar_ Před měsícem

    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.

  • @stith_pragya
    @stith_pragya Před 8 měsíci +1

    Thank You So for this wonderful video.........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @vikasbagri1225
    @vikasbagri1225 Před rokem

    understood it very well...

  • @harshvardhansingh2272

    understood striver
    great explanation

  • @subhamoybera6456
    @subhamoybera6456 Před rokem

    Great explanation 👍

  • @sripriyapotnuru5839
    @sripriyapotnuru5839 Před rokem

    Thank you, Striver 🙂

  • @tawkeer4
    @tawkeer4 Před 4 měsíci

    The command you have over graph problems is 🔥🔥

  • @sagartaak4017
    @sagartaak4017 Před rokem

    Best explanation 💥

  • @VedPrakashLearnToGrow

    Thanks for amazing explanation

  • @shyren_more
    @shyren_more Před 2 lety

    understood, thanks!

  • @bhavkushwaha
    @bhavkushwaha Před 25 dny

    Understood Striver, Thankyou!

  • @mananarora141
    @mananarora141 Před rokem +1

    UNDERSTOOD!!!

  • @suheabkhan2546
    @suheabkhan2546 Před 2 lety

    understood very good

  • @_jasneetsingh_
    @_jasneetsingh_ Před rokem

    thank you so much. God Bless Us

  • @pranavmaniyar9901
    @pranavmaniyar9901 Před rokem

    understood , op explaination

  • @user-kl3qv1sc8k
    @user-kl3qv1sc8k Před 2 měsíci

    Understood Striver, thanks a lot

  • @kirtitung4877
    @kirtitung4877 Před 2 lety

    Thank you so much bro!!!!

  • @manavnaharwal1921
    @manavnaharwal1921 Před 2 lety

    Understood 🙌

  • @shubhigupta5689
    @shubhigupta5689 Před rokem

    Understood🌻

  • @user-kk5vn5nf5v
    @user-kk5vn5nf5v Před 6 měsíci

    best explanation☺

  • @himangshubiswas542
    @himangshubiswas542 Před rokem

    I love ur opening line

  • @shivisingh9975
    @shivisingh9975 Před měsícem

    Understood sir !

  • @arnabroy2995
    @arnabroy2995 Před rokem

    understood well

  • @huungryyyy
    @huungryyyy Před 23 dny

    understood striver

  • @LBK3
    @LBK3 Před rokem

    Understood ❤

  • @vipulmaheshwari2321
    @vipulmaheshwari2321 Před rokem +1

    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.

  • @Codekage1
    @Codekage1 Před rokem +1

    Understood!

  • @UECAshutoshKumar
    @UECAshutoshKumar Před 11 měsíci +1

    Thank you sir

  • @RohitKumar-dz8dh
    @RohitKumar-dz8dh Před 2 dny

    Understood 😊

  • @user-tk2vg5jt3l
    @user-tk2vg5jt3l Před 3 měsíci

    Thank you bhaiya

  • @shyren_more
    @shyren_more Před 2 lety

    defining the dfs/bfs function as private is just a good code practice or does it have some other reason?

  • @p38_amankuldeep75
    @p38_amankuldeep75 Před rokem

    understood💙💙💙

  • @hashcodez757
    @hashcodez757 Před 10 měsíci

    understood !!

  • @KratosProton
    @KratosProton Před 2 lety

    Understood sirji

  • @debadritadutta2308
    @debadritadutta2308 Před rokem

    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?

  • @sbrosgamerz3470
    @sbrosgamerz3470 Před rokem +1

    One man teaching entire India the best for free 🙂🙂🙂

  • @_hulk748
    @_hulk748 Před rokem

    Understood sir🙇‍♂❤🙏

  • @adityasaxena6971
    @adityasaxena6971 Před rokem

    Understood💯💯

  • @prajwalhorti3717
    @prajwalhorti3717 Před rokem

    understood!

  • @lakshsinghania
    @lakshsinghania Před rokem

    was able to do the bfs on my own
    :)

  • @AbhishekPandey-yl3bp
    @AbhishekPandey-yl3bp Před rokem

    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

  • @adarshkumarrao3478
    @adarshkumarrao3478 Před rokem +1

    understood

  • @akshanshsharma6025
    @akshanshsharma6025 Před rokem +1

    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

    • @taneyasoni
      @taneyasoni Před rokem

      can you share the bfs code? i wrote bs code and it gave me TLE

    • @shrujaigupta2586
      @shrujaigupta2586 Před 11 měsíci +1

      try to check if you addded the condition of checking whether the node is visited or not@@taneyasoni

    • @taneyasoni
      @taneyasoni Před 11 měsíci +1

      thank you@@shrujaigupta2586

  • @getgoin2217
    @getgoin2217 Před rokem +6

    @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

    • @tg62672
      @tg62672 Před rokem

      it gave me stack overflow error until i added a visited array.

    • @ultimatecreed5144
      @ultimatecreed5144 Před rokem

      thanks bro been searching this for 1/2 hour thanx

  • @md.sajidhossain3146
    @md.sajidhossain3146 Před rokem

    Take love from Bangladesh

  • @morganyu3391
    @morganyu3391 Před 2 lety

    Understood bhaiya

  • @raushankumar6993
    @raushankumar6993 Před 9 měsíci

    thanks

  • @Aryan-gn9ux
    @Aryan-gn9ux Před 9 měsíci

    Understood!

  • @dreamyme543
    @dreamyme543 Před rokem

    Understood:)

  • @surajpalsau870
    @surajpalsau870 Před rokem +1

    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

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

    Thanks. Understood

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

      Bro Time Complexity wala part thoda explain kar skte ho?? Smjh nhi aaya mujhe

  • @satendra6200
    @satendra6200 Před 9 měsíci

    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

  • @mriduljain1981
    @mriduljain1981 Před rokem

    understood.

  • @ganeshmula4508
    @ganeshmula4508 Před rokem

    understood sir

  • @nextnotification9857
    @nextnotification9857 Před 4 měsíci

    solved on my own before watching the video using dfs🙂

  • @SumitKeshariMCS
    @SumitKeshariMCS Před rokem +6

    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

  • @vamsimadugula8524
    @vamsimadugula8524 Před rokem +1

    first time i solved a question on my own 🥺

  • @ayushgaurabh8604
    @ayushgaurabh8604 Před 2 měsíci

    awesome

  • @sukritinarang5016
    @sukritinarang5016 Před rokem

    understood :)

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

    Got tle in the same question at code studio. Any optimisation in same code?

  • @chitranshjain5075
    @chitranshjain5075 Před 2 lety

    Understood.

  • @csea_37_shayoribhowmick53

    Thank you so much

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

    BESTTT BESST TEACHHERRR

  • @harshdasila6680
    @harshdasila6680 Před 2 lety

    understooodddddd