G-15. Number of Enclaves | Multi-source BFS | C++ | Java

Поділитися
Вставка
  • Опубліковано 22 гру 2024

КОМЕНТАРІ • 256

  • @takeUforward
    @takeUforward  2 роки тому +41

    Let's continue the habit of commenting “understood” if you got the entire video. Please give it a like too, you don't 😞
    Do follow me on Instagram: striver_79

    • @sukhpreetsingh5200
      @sukhpreetsingh5200 2 роки тому +2

      love u bhaiya I am able to solve it myself

    • @suhaanbhandary4009
      @suhaanbhandary4009 Рік тому +1

      I like and comment on every video after doing the problem, it has become a muscle memory, as the explanation is best, Completed DP series now revising graph through the playlist

  • @naveensaicremsiyadlapalli3769
    @naveensaicremsiyadlapalli3769 2 роки тому +168

    I solved this problem even without watching the lecture I am able to get the intuition thanks striver

  • @rahulsaha332
    @rahulsaha332 2 роки тому +87

    Your surrounded regions intuition was mindblowing, certainly grown interest in BFS and DFS on grids. Thank you striver. Could able to solve the problem on my own

    • @priyanshkumar17
      @priyanshkumar17 7 місяців тому +1

      Yes, I've also greater interest in BFS and DFS on grids than before.

  • @vaidanshkukreja8970
    @vaidanshkukreja8970 2 роки тому +29

    Finally Solved Myself the whole question without looking into the solution even for a second. Thank you so much Striver bhaiya for brainstorming and taking me to the next level.
    Literally u take me forward!! 🔥🔥🔥🔥🔥

  • @unknown2003august
    @unknown2003august 5 місяців тому +17

    AT first i though it can be complex but after reading so many positive comment i gave try ,and in just one time it got solved ..
    ITNIIIIIII KHUSHIIIIIIII😭😭😭😭😭😭

    • @AverageIndianDrivers
      @AverageIndianDrivers 12 днів тому

      after reading ur comment i tried on my own aur hogya wow thnkeww anyways for commenting

  • @ninadkheratkar6716
    @ninadkheratkar6716 Рік тому +3

    Your Surrounded Regions approach helped a lot with this code, was able to solve this on my own. Thank you for the entire graph playlist, really appreciate what you are doing for the CS community!

  • @SumitKeshariMCS
    @SumitKeshariMCS 2 роки тому +35

    We can use the concept of Surrounded regions to solve this problem. The concept of BFS is also amazing. Thanks Striver. Solved it on my own using DFS :)

    • @aniketrai9643
      @aniketrai9643 Рік тому +2

      bro even i tried dfs but im getting Runtime error can u share ur code

    • @SumitKeshariMCS
      @SumitKeshariMCS Рік тому

      @@aniketrai9643 Hi Aniket. Here is the code:
      I coded it on LeetCode:
      class Solution {
      private:
      void dfs(vector& mat,vector& visited,int row,int col,int delRow[],int delCol[])
      {
      visited[row][col]=1;
      for(int i=0;i=0 && nrow=0 && ncol

    • @ravisingh-el8np
      @ravisingh-el8np Рік тому

      @@aniketrai9643
      void dfs(auto & grid , auto & visited, int n,int m , int r , int c){
      visited[r][c] = true;
      pair arr[] = {{-1,0},{1,0},{0,-1},{0,1}};
      for(int k=0;k=0 && newr =0 && newc

    • @kabirbhawar3908
      @kabirbhawar3908 Рік тому

      @@aniketrai9643 Same lol

    • @shreyarawatvlogs6920
      @shreyarawatvlogs6920 11 місяців тому

      can you kindly share your code

  • @worldofniyathi
    @worldofniyathi 6 місяців тому +5

    i solved this question on my own, by watching the previous video, thank you so much.

  • @kaushikpilligundla
    @kaushikpilligundla Рік тому +3

    This is undoubtedly the best content out there on the internet to learn graph problem. I was able to solve this problem without looking at the solution.
    I was intimidated by graph problem but now it's safe to say that I am really enjoying them.
    I am super grateful for your work Raj.
    Thank you so much!

  • @AnkitRawat-bi1rj
    @AnkitRawat-bi1rj 7 місяців тому +2

    In love with this graph series, so far it's been very easy journey and it's just because of your teaching striver, thank you so much !!

  • @tatasays0029
    @tatasays0029 Рік тому +2

    I literally backtracked to like the videos after completing the series and stopped here😅.
    Loved it!!! UNDERSTOOD

  • @CRICTHAT11
    @CRICTHAT11 11 місяців тому +1

    Thank you so much Striver bhaiya. Earlier I was so scared of graphs but now I am able to solve questions on my own thank you so much. I am so grateful to you for this valuable content 🤗

  • @shubhambhosle8107
    @shubhambhosle8107 Рік тому +2

    Thank You for such a wonderful graph series, just addicted to solving graph problems ❤

  • @divyashanmugam161
    @divyashanmugam161 11 місяців тому

    Thanks so much. I'm following your graph series and this was one of the tough topics for me. I was able to solve this problem without watching this video. All other videos are also great for understanding. I never thought i would be able to solve any graph problem on my own. !!! thanks again.

  • @cinime
    @cinime 2 роки тому +2

    Understood! What a super amazing explanation as always, thank you very much!

  • @bmishra98
    @bmishra98 2 місяці тому

    I solved it without even seeing your solution, using DFS as you taught in previous video. Thanks Striver.

  • @vivekswami2182
    @vivekswami2182 2 роки тому

    Solved the problem without even looking at the video only because of you Striver !! Thanks !!

  • @devamaniduddekunta3621
    @devamaniduddekunta3621 Рік тому +1

    the largest treasure for graph series..tqsm for making such an amazing series...

  • @kunalwadhai777
    @kunalwadhai777 Рік тому

    I doesn't even know detail or an intermediate about dfs and bfs but the explanation that you had made was pretty much cool. Thank you sir for providing such content.

  • @khyatikakkar9259
    @khyatikakkar9259 7 місяців тому

    I solved this problem without even watching the video.
    Thank you so much striver for making such a tough topic my cup of tea.

  • @prakashraushan2621
    @prakashraushan2621 Рік тому

    was too afraid of graph earlier. but as soon as started this series, intutions got stronger. Now as the lectures are increasing, i'm more able to solve questions.

  • @secondarypemail7181
    @secondarypemail7181 2 роки тому +2

    Similar to the last question ,hence building an intuition was easier .Thanks

  • @prathambhushan4859
    @prathambhushan4859 6 місяців тому

    Finally Solved Myself the whole question without looking into the solution even for a second. thank u❤

  • @preetkatiyar969
    @preetkatiyar969 2 роки тому +4

    Really sir you make graph very easy and you can teach any tough concept of world in very simple manner . Thank you so much Striver sir.

  • @siddwivedi9643
    @siddwivedi9643 Рік тому

    Solved the question by myself without starting the video!! thank you so much for this series striver

  • @shaddyrogue9430
    @shaddyrogue9430 2 роки тому +1

    Understood I could do it using dfs because I understood the last video on Surrounded region . Thanks for great Logic..

  • @Saurabh-fe2bg
    @Saurabh-fe2bg Рік тому +1

    Amazing question selection!!!all are linked to each other

  • @maityamit2003
    @maityamit2003 2 роки тому

    I solved this problem even without watching the lecture I am able to get the intuition thanks striver
    Solved this Surrounded Regions Intuition 😁😁😁😁

  • @manasansh7198
    @manasansh7198 Рік тому

    I was able to solve the whole question without even looking at solution thank you for such amazing quality content

  • @sksanoyarali1067
    @sksanoyarali1067 9 місяців тому

    I solved the problem with same intuition of DFS on surrounded region it's actually almost same .thank striver ❤

  • @_ShreyaSingh-wv4qz
    @_ShreyaSingh-wv4qz Рік тому

    2nd problem solved by me..THANK YOU STRIVER BHAIYA..AAP TO DEVTA HAI🙌

  • @adityavarma1334
    @adityavarma1334 Рік тому

    Great sir ji, Kaash life bbhi itni hi asani se samjh aa jaati🙂

  • @piyushsonawane120
    @piyushsonawane120 Місяць тому

    Solved this problem on my own based on previous problem intuition 💯.

  • @saibharath788
    @saibharath788 Рік тому +1

    very easy explanation. Hope to learn more from you

  • @cutefunnyanimals7338
    @cutefunnyanimals7338 Рік тому

    Awesome, was able to get the intuition and solve without watching the solution based on previous video..

    • @neymarfan4023
      @neymarfan4023 Рік тому

      He solved that problem by dfs here he did it with bfs

  • @ravikiranreddy2867
    @ravikiranreddy2867 Рік тому +1

    ONE CHANGE (REQUIRED),I think we can check whether it is visited or not after popping from queue also , in this we need not required to start from boundary all the time

  • @zebra-er6xc
    @zebra-er6xc Рік тому +1

    i could do this question by myself, thanks striver

  • @aryashjain7893
    @aryashjain7893 2 роки тому

    understood , last wala hi itna sahi samjhaya ye wala video hi nahi dekhna pada did on my own

  • @muditkhanna8164
    @muditkhanna8164 Рік тому

    I really got to know the meaning of "if it works don't touch it" quote, here it is applicable at 14:32 , you can see that in line 53.
    instead of && , & worked because they were both true (1) and 1 &1 =1 =true .

  • @thebestview8411
    @thebestview8411 3 місяці тому

    Thank you Striver, Becoz of you I solved this problem on my own. 😁

  • @PiyushWagh-w5m
    @PiyushWagh-w5m 2 місяці тому

    Thank you very much for your best explanation.

  • @manish_sarswat_iiitg
    @manish_sarswat_iiitg Рік тому

    i applied dfs without watching videos,this would only happened becuase of previous videos ,thanks striver bhaiya ,bhagwan aapka bhala kre 🙏🙏

  • @arkasheikh3539
    @arkasheikh3539 2 роки тому +1

    Could able to solve the problem on my own you are really taking us forward

  • @harshitraj8409
    @harshitraj8409 2 роки тому

    Thank you striver bhaiya. Solved the problem on my own. But still watched whole video.

  • @UECSoumyaRay
    @UECSoumyaRay Рік тому +1

    Was able to do this without watching the lecture. Getting the intuition slowly, one step at a time! Thanks Striver.

  • @sumerrawat6947
    @sumerrawat6947 2 роки тому +1

    One thing I must learn is to write the code in such a way that there is no chance of syntax and logical errors ! and my code runs in one go

  • @sanjanajhawar9982
    @sanjanajhawar9982 Рік тому

    Hats off to your explanations !! Helped me a lot , thank you so much !!

  • @suhaanbhandary4009
    @suhaanbhandary4009 Рік тому

    understood, did it in the first go without watching the video, because of previous videos

  • @TunedToThrive
    @TunedToThrive Рік тому

    Understood. wonderful videos. so clearly explained. kudos to you :)

  • @raghavsahay6987
    @raghavsahay6987 Рік тому

    i was able to solve this qestion on my own ,thank you striver

  • @UECAshutoshKumar
    @UECAshutoshKumar Рік тому +1

    Thank you sir 😊

  • @aditya_raj7827
    @aditya_raj7827 9 місяців тому

    Understood bhaiya❤😊

  • @ankitranjan88
    @ankitranjan88 2 роки тому

    I solved it on my own ... Thanks Bhaiya ❤.

  • @vakhariyajay2224
    @vakhariyajay2224 2 роки тому

    Thank you very much. You are a genius.

  • @DevashishJose
    @DevashishJose 11 місяців тому

    Understood, Thank you so much.

  • @rishabhshairy972
    @rishabhshairy972 Місяць тому

    Solved it using DFS based on Concept of Surrounding regions

  • @mriduljain6809
    @mriduljain6809 Рік тому

    Understood Bhaiya...

  • @lapimpale
    @lapimpale 2 роки тому +4

    Understood bro.
    Why we did not traverse on perimeter and sunk all the lands by marking them 0 connecting to perimeter with DFS? in the end, we check how many 1s are there in the grid and return the ans. It will save space too. What was the risk?

    • @takeUforward
      @takeUforward  2 роки тому +4

      We usually don’t tamper with the data, we just return the final form of transformation which is needed.
      Imagine in a real life scenario, you are asked to modify some data, and in order to modify those specific points, you use a logic which harms others, it fixes it afyerwards, but it does harm it for some time, so we don’t do it 😄

    • @lapimpale
      @lapimpale 2 роки тому +4

      @@takeUforward understood. The moto is not only to solve the problems but also to be a clean coder 😀

    • @anshgupta3222
      @anshgupta3222 2 роки тому

      As he has said many times before, you shouldn't be altering the data given as that's how things work in real life as well. Therefore, used the vis array for checking. Your approach is right and would give you the result as well.

  • @_hulk748
    @_hulk748 Рік тому

    Thankyou sir Understood sir ❤🙇‍♂🙏

  • @TravelTracksByDebo
    @TravelTracksByDebo 2 роки тому

    understood bhaiya .......wonderful explanation

  • @ssv6055
    @ssv6055 2 роки тому +1

    i did such a silly mistake debug karte karte time laggaya .. yr...Arigato bhaiya

    • @sumerrawat6947
      @sumerrawat6947 2 роки тому

      silly mistakes bhut time khaa jaati hai bhai

    • @ssv6055
      @ssv6055 2 роки тому +1

      @@sumerrawat6947 ha bro..🥲

  • @Sillysmiles76
    @Sillysmiles76 Рік тому

    Understood, Thank you

  • @creatorstudio5945
    @creatorstudio5945 Рік тому

    terrific explanation

  • @subhamoybera6456
    @subhamoybera6456 Рік тому

    Great explanation 👍

  • @harshvardhansingh2272
    @harshvardhansingh2272 2 роки тому

    understood striver
    did this on my own after getting the intuition
    great explanation as always

  • @vrandakansal5940
    @vrandakansal5940 Рік тому

    even without watching the lecture I am able to solve the problem on my own

  • @lakshsinghania
    @lakshsinghania Рік тому

    understood!!
    solved it on my own :)

  • @kapilsingh2816
    @kapilsingh2816 Рік тому +1

    it was my first qsn which i solved without watching the soln

  • @magicreborn3720
    @magicreborn3720 9 місяців тому

    amazing explanation!!

  • @parshchoradia9909
    @parshchoradia9909 Рік тому

    Understood Sir!

  • @akshatsharma_iiti
    @akshatsharma_iiti 3 місяці тому

    bhrata shri, what if we need to return the no. of islands/enclave-groups? 🤔

  • @shyren_more
    @shyren_more 2 роки тому

    Understood, thanks!

  • @suryakiran2970
    @suryakiran2970 Рік тому

    Understood❤

  • @anshuman8147
    @anshuman8147 9 місяців тому

    I solved it using dfs on my own Im very happy haha😅

  • @p38_amankuldeep75
    @p38_amankuldeep75 2 роки тому

    understood💙💙💙

  • @coderaman_tech
    @coderaman_tech Рік тому +2

    Is anyone getting TLE by dfs approach discussed in previous lecture approach?

  • @dreamyme543
    @dreamyme543 2 роки тому +1

    Understood:)

  • @Ramu9119
    @Ramu9119 11 місяців тому

    Great Video

  • @aniketchaudhary5803
    @aniketchaudhary5803 2 роки тому

    Understood 😃

  • @ujjwalraj9837
    @ujjwalraj9837 Рік тому +1

    It's liteally the same question as the last one (previous video of the playlist)

  • @DeadCode_Debugs
    @DeadCode_Debugs 2 місяці тому

    i solved this without watrching tutoarial , just refered the prev video by myself and tried ,, and it submitted in one

  • @DanielAmoateng-q8k
    @DanielAmoateng-q8k Рік тому

    Thank you

  • @akshanshsharma6025
    @akshanshsharma6025 Рік тому

    you know guys i tried this question by using dfs so that i take a visited 2d matrix but if i take a visited 2d matrix i get time limited exceed but when i manipulate the same grid data my code submit successfully by the way great explanation
    i mention both the code here
    void dfs(int row,int col,vector&grid,int n,int m)
    {
    grid[row][col]=0;
    int drow[]={-1,1,0,0};
    int dcol[]={0,0,-1,1};
    for(int i=0;i=0 && r=0 && c

    • @pranjalsharma346
      @pranjalsharma346 Рік тому

      TLE is not due to the use of a visited matrix it might be due to not passing the grid matrix by reference.

  • @dhruvilprajapati4734
    @dhruvilprajapati4734 Рік тому

    solved without watching video thanks

  • @himaniupadhyay8201
    @himaniupadhyay8201 Рік тому

    Thank U soo Much

  • @akashsahu2571
    @akashsahu2571 Рік тому

    yes

  • @adarshkumarrao3478
    @adarshkumarrao3478 Рік тому

    UNDERSTOOD

  • @stranger1967
    @stranger1967 Рік тому

    understood sir

  • @manasranjanmahapatra3729
    @manasranjanmahapatra3729 2 роки тому

    Understood!

  • @amanbhadani8840
    @amanbhadani8840 2 роки тому

    its just a piece of cake too.

  • @DeadPoolx1712
    @DeadPoolx1712 20 днів тому

    UNDERSTOOD;

  • @sanjaysubramani4041
    @sanjaysubramani4041 6 місяців тому

    Able to solve on my own

  • @prajwalhorti3717
    @prajwalhorti3717 2 роки тому

    understood!

  • @nonplussedNerd
    @nonplussedNerd Рік тому

    isnt it the same as surrounded regions , just make a counter at the end how many 1s are left in grid

  • @shreyarawatvlogs6920
    @shreyarawatvlogs6920 11 місяців тому

    its showing runtime error. WHY????

  • @Aviral-rk6li
    @Aviral-rk6li 6 місяців тому

    hey , i am getting memory limit exceeded on the last test case.Through DFS.can someone please help

  • @morrisonsempire9354
    @morrisonsempire9354 Рік тому

    I dont know why but instead of using the nested loops when i use 2 seperate loops similar to the previous video it gives wrong answer for this ip 0 0 0 0
    1 0 1 0
    0 1 1 0
    0 0 0 0
    expected output is 3 but it gives 0 when i use individual loops for bfs call.

  • @beginnertopro7265
    @beginnertopro7265 2 роки тому +2

    Bhaiya by using DFS ,
    TLE de rha hai

    • @beginnertopro7265
      @beginnertopro7265 2 роки тому

      In last two case me de rha hai

    • @yabhishakekumar825
      @yabhishakekumar825 2 роки тому

      Working DFS :
      void fill(vector &grid,int row,int col,int delRow[],int delCol[]){
      grid[row][col] = 0;
      for(int i=0;i=0 && nRow=0 && nCol

  • @shashankchandak2238
    @shashankchandak2238 2 роки тому

    It is very much similar to the rotten oranges problem🤔.

  • @yashgupta6846
    @yashgupta6846 2 роки тому

    Understood sir