G-14. Surrounded Regions | Replace O's with X's | C++ | Java

Поделиться
HTML-код
  • Опубликовано: 25 дек 2024

Комментарии • 305

  • @takeUforward
    @takeUforward  2 года назад +105

    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 года назад +1

      I am able to solve this question myself!! thanks a lot all this is because of you....

    • @jatilyadav4000
      @jatilyadav4000 2 года назад

      understood.... Best explaination

    • @sanchittripathi1537
      @sanchittripathi1537 Год назад

      understood

    • @im2opyt177
      @im2opyt177 Год назад

      bhiya why cant we have no visited matrix in this soln,we can use the matrix given to us and to record the visited we can change it to '1' and while backtracking we can undo the changes

    • @challasusmithachallasusmit9921
      @challasusmithachallasusmit9921 3 месяца назад

      Understood Everything Thank you so Much

  • @shivyanshgarg2641
    @shivyanshgarg2641 Год назад +39

    I am so happy to share that from lec 9 10 12 13 14 . I am able to solve them by myself without watching the whole video. After my solution gets accepted . I come and watch your video at 2x

  • @anushkajain1843
    @anushkajain1843 Год назад +68

    The logic was really great.
    We instead of finding who will be marked cross , we found out who will not through the boundary connection condition .
    Kudo striver for making this series.

  • @ShaliniNukella
    @ShaliniNukella 10 месяцев назад +8

    You've worked really hard to make these videos, mainly without getting irritated, you've coded each and every part. I realised how much time and PATIENCE is required to do that.... Thanks a lot

    • @rickk3300
      @rickk3300 7 месяцев назад

      Yeah, this is the best thing about Striver's videos!! He is EXTREMELY PATIENT while explaining any logic and coding it up till the end!! Just follow his recursion series, you will get to know how much patient he can be...

  • @arunachalamm3399
    @arunachalamm3399 5 месяцев назад +3

    saw 3 min, found intuition thanks to striver bhai and coded it, got AC, came and watched entire video to contribute to takeUForward's watch time and recommendation

  • @HarshRaj-kk7rd
    @HarshRaj-kk7rd Год назад +13

    the energy you bring while teaching is just amazing

  • @abdalla4425
    @abdalla4425 11 месяцев назад +3

    I know it had something to do with border and how they connect. First attempt was to try to find which ones reach the border but then I realized it would be easier to find what ones the border reaches. From their I had it down, solved it, and watched the video as a refresher/check for tips or tricks.

  • @sahilbani7020
    @sahilbani7020 7 месяцев назад +5

    love how after his all set of examples and intuitions, everything just falls in place perfectly

  • @tasneemayham974
    @tasneemayham974 10 месяцев назад +1

    Honestly, Striver!! Amazing LOGIC! If we think of it like you did it becomes a walk in the park!!
    UNDERSTOODD!! THANK YOUUU!!

  • @009_akshayrajput
    @009_akshayrajput Год назад +1

    "Understood", Marvelous explanation with high energy !!

  • @saurabhtiwari287
    @saurabhtiwari287 2 года назад +5

    Maza aa gya bhayiya ☺☺☺
    Lg hi nhi rha tha ki hard problem kr rhe h. Aaisa level set kr dya aapne hm sbka

  • @vadheraproductions1218
    @vadheraproductions1218 7 месяцев назад

    i just saw your explanation of what the problem really is in the first few minutes, and then coded it using dfs and passes all the test cases on leetcode, thankyou so much striver , its due to your teaching that i am elevating my coding skills each day

  • @albatrossgeez6637
    @albatrossgeez6637 Год назад +1

    Striver bro!!! I just want to hug you.............lots of respect and love and keep doing what you are doing...

  • @sonugupta147
    @sonugupta147 10 месяцев назад +3

    My initial thoughts: start the ans matrix of size m*n with 'X's. If we have any 'O's on the boundary, treat them as a door or entrance and apply DFS from that cell. The DFS will make sure that it covers every O's cells which are connected to this entrance. Once DFS is done it would have marked all the affected cells as O's and rest are just 'X's. So in this way all the O's cells surrounded by boundary of X's will be marked as X.

  • @NaveensinglaYT
    @NaveensinglaYT 2 года назад +14

    such a good and refined series absolutely loved it striver bhai

  • @Anoyashu
    @Anoyashu Год назад +5

    till now in graph series, its all about how well we have understood DFS or BFS , rest is variation !!!

  • @introvert3487
    @introvert3487 2 года назад +5

    Barhe log aa gye ...love you warsaw bhaiya ❤️

  • @Benstokes555
    @Benstokes555 8 месяцев назад +1

    YOURE MY DIAMOND STRIVES :)

  • @vipulchaudhary_js
    @vipulchaudhary_js 2 года назад +6

    I was trying to solve this question on leetcode this evening and Guess what You uploaded a solution!

  • @sayandey2492
    @sayandey2492 Год назад +3

    Able to solve the problem just by seeing till 2:40 of the video...power of Strivers 😎

  • @santanu29
    @santanu29 Год назад +5

    19:30 I think rather than creating delRow and delCol arrays you can just mention the dfs function call 4 times. I will save a lot on the parameters per call.
    Code:
    void dfs(int row, int col, vector& mat, vector& vis)
    {
    if(row

    • @arshdeep011
      @arshdeep011 Год назад

      Time limit exceeds : 1032/1044 passed

    • @rushidesai2836
      @rushidesai2836 Год назад

      @@arshdeep011 Are you the cricketer Arshdeep Singh?

    • @arshdeep011
      @arshdeep011 Год назад

      @@rushidesai2836 I don't watch cricket

  • @arthurdark3945
    @arthurdark3945 2 года назад +14

    Awesome series! Can you cover graph questions that were asked in OAs in your experience or someone else's so that we can learn what type of questions are actually asked?

    • @chandannikhil8526
      @chandannikhil8526 2 года назад +11

      Bhai gfg ke jobhathon dekho almost every contest mai hard ques graph based hote hai use bhaiya samjhate hai contest review mai

    • @arthurdark3945
      @arthurdark3945 2 года назад +1

      @@chandannikhil8526 Thank you will check those videos out

  • @roydebraj2188
    @roydebraj2188 5 месяцев назад

    striver thanks alot fot your effort in making such an amazing in depth free course , i just watched you first 6 - 7 videos and i am telling you i am able to solve medium level questions on leetcode it really boost up up confidence thanks alot striver

  • @1tav0
    @1tav0 2 года назад +6

    Awesome, thank you striver as always understood

  • @ASHISHKUMAR-o4c6x
    @ASHISHKUMAR-o4c6x Год назад +1

    because of you i am easily able to understand graph
    thank you sir......

  • @juniorboy1903
    @juniorboy1903 2 года назад +1

    Aap question aur code dono ko bahut easy bana dete ho bhaiya😀😍

  • @kaimadamantonyshejin2034
    @kaimadamantonyshejin2034 2 года назад +3

    I understood your explanation, paused your video and tried it with BFS, it worked. Amazing explanation

  • @stith_pragya
    @stith_pragya Год назад +1

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

  • @VivekVerma-oo3dx
    @VivekVerma-oo3dx Год назад

    able to do this question without watching the solution it really boosted my confidence thaku striver

  • @pulkitchausali1354
    @pulkitchausali1354 Год назад +1

    day by day getting confidence while doing graph question able to solve this question myself #thanks Wizard Striver

  • @rohan8758
    @rohan8758 7 месяцев назад +1

    Great explanations, I was wondering here for complex problem solution I am getting training as doctor strange got from guru maa in kathmandu!

  • @monty6393
    @monty6393 2 года назад +4

    Oho man just did number of island Question on leetcode :) it was a daily challenge problem exactly the same type of Question like this one :) ..did with recursion went up ,down left, right and follow up the constraints :)

  • @harshvardhansingh2272
    @harshvardhansingh2272 2 года назад +1

    understood striver
    Awesome explanation as always

  • @manojnavinjamuri5867
    @manojnavinjamuri5867 2 года назад +3

    thank you striver for creating such amazing content

  • @syedmohammadhussain7137
    @syedmohammadhussain7137 2 года назад +1

    thanks man,same question came in my cohesity interview 40lpa

  • @ankitranjan88
    @ankitranjan88 2 года назад +1

    Solved this one by self on BFS and DFS Both.

  • @Fighter_Believer_Achiever
    @Fighter_Believer_Achiever 2 дня назад

    Graph is such a nice topic.

  • @DevashishJose
    @DevashishJose 11 месяцев назад

    Understood, Thank you so much, this was such a beautiful solution.

  • @sakshisahu3983
    @sakshisahu3983 2 года назад +1

    Thank you striver for all your efforts.

  • @rakshitharsh6169
    @rakshitharsh6169 Год назад +1

    excellent explanation!

  • @harleenkaur7751
    @harleenkaur7751 2 года назад +1

    Thanks a lotttt striver for such an amazing playlist

  • @conceptualboy_vikash
    @conceptualboy_vikash Год назад

    kaya bat hai baiya ,maza aagya apka obserwation se

  • @RohitKumar-dz8dh
    @RohitKumar-dz8dh Год назад +1

    Understood 😊

  • @vatsalvasoya5243
    @vatsalvasoya5243 Год назад

    Understood!! Very well explained!!!

  • @top_g755
    @top_g755 Год назад +1

    This question can also be done like previous one using bfs we just. Need to put zero which are at the boundary in the queue then we have to run while loop until queue becomes empty and parallely we need to mark visited to the neighbouring zeros of boundary zeros....then we have to convert zero to x which are not visited 😅

  • @chandannikhil8526
    @chandannikhil8526 2 года назад +2

    Understood bhaiya i have done bfs traversal

  • @subhamoybera6456
    @subhamoybera6456 Год назад +1

    Great explanation 👍

  • @HEMANTPORWAL-t7d
    @HEMANTPORWAL-t7d 7 месяцев назад

    Nice explaination sir but now gfg has increased test cases to 1,120 and with this approach only 1,116 test cases are getting passed
    thank u for your efforts

  • @codewithom11
    @codewithom11 Год назад +1

    Majaa Aagaya😜

  • @dharsan.s7937
    @dharsan.s7937 2 года назад +1

    Legend is back

  • @kshithi2864
    @kshithi2864 2 года назад

    Understood😁Thanks a lot Striver😃

  • @shreyasinha4016
    @shreyasinha4016 2 месяца назад

    solved on my own without watching the video on basis of prev videos and now watching

  • @sripriyapotnuru5839
    @sripriyapotnuru5839 2 года назад

    Thank you, Striver 🙂

  • @kaichang8186
    @kaichang8186 3 месяца назад

    understood, thanks for the effort on the great video

  • @susanthomas223
    @susanthomas223 10 месяцев назад

    Thank you so much for such a detailed video

  • @rishucs3240
    @rishucs3240 Год назад +1

    understood very well!!!

  • @vakhariyajay2224
    @vakhariyajay2224 2 года назад

    Thank you very much. You are a genius.

  • @RajeshKumar._.16
    @RajeshKumar._.16 Год назад

    very nice approach and explanation

  • @goatwice
    @goatwice 5 месяцев назад +1

    using jS one can make a game that contain the player which is surrounded by a protection layer and enemy can enter through the boundry points

  • @rishabhagarwal8049
    @rishabhagarwal8049 2 года назад

    Understood Sir, Thank you very much

  • @developer00007
    @developer00007 7 месяцев назад +1

    Understood the solution in first 6 mins.
    Paused the video and solved the question in 10 mins 😉

  • @suhaanbhandary4009
    @suhaanbhandary4009 Год назад

    understood, thanks for such playlist!!

  • @Sumeet_100
    @Sumeet_100 Год назад

    Thank You striver Bhaiya 🤟

  • @albatrossgeez6637
    @albatrossgeez6637 Год назад

    You are my inspiration ......................hats offfffffffffffffffffffff

  • @Fighter_Believer_Achiever
    @Fighter_Believer_Achiever 2 дня назад

    Thank you very much sir!!!

  • @gangsta_coder_12
    @gangsta_coder_12 2 года назад +1

    Understood 😀😀

  • @rrp3509
    @rrp3509 2 года назад +3

    Superb as usual. But the first time I found energy and excitement low during explanation.
    Keep your uniqueness full of energy and excitement.❤️

    • @takeUforward
      @takeUforward  2 года назад +11

      Repeated questions, new questions excite me ;)

    • @RohitSharma-yc8lm
      @RohitSharma-yc8lm 2 года назад

      @@takeUforward 💛 thank you so much striver for these playlists , i learned recursion tree dp nd now graphs too.

  • @champion5946
    @champion5946 2 года назад +1

    // To traverse the boundary
    for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
    if ((i == 0 || i == n - 1) || (i > 0 and i < n - 1 and (j == 0 || j == m - 1))) {
    // ToDo
    }
    }
    }

  • @RohitSharma-yc8lm
    @RohitSharma-yc8lm 2 года назад +1

    #UNDERSTOOD

  • @maheshdhage5328
    @maheshdhage5328 2 года назад

    always love ur vidos and u brother😍

  • @aparna5364
    @aparna5364 2 года назад +1

    Understood 🙂

  • @suryanshsingh6423
    @suryanshsingh6423 6 месяцев назад

    God of dsa🙏

  • @parshchoradia9909
    @parshchoradia9909 Год назад

    Understood Sir!

  • @CodeMode9313
    @CodeMode9313 Год назад

    ek dum mast

  • @mihirsaini592
    @mihirsaini592 2 года назад

    Great intuition

  • @mananarora141
    @mananarora141 Год назад

    UNDERSTOOD!!!!!!!!

  • @nishantsah6981
    @nishantsah6981 2 года назад +13

    Will it be a good practice if in dfs traversal I change the boundary connected component to some random character (suppose 'Y') and then traverse the matrix where ever I find a 'O' I convert it to 'X' and change those 'Y' back to 'O'....ultimately this will change only the required 'O' ->'X'

    • @takeUforward
      @takeUforward  2 года назад +8

      you can! the main aim of the video is to teach that dfs or bfs can be used to solve the problem, can have various approaches.

    • @yashupadhyay6985
      @yashupadhyay6985 Год назад

      i did the same

  • @UECAshutoshKumar
    @UECAshutoshKumar Год назад +1

    Thank you sir

  • @gunahawk6893
    @gunahawk6893 2 года назад

    just watched 1 min and solved the whole problem damn

  • @studyonline3236
    @studyonline3236 2 года назад

    Thanks you very much bro for the series

  • @herculean6748
    @herculean6748 2 года назад

    thanks striver🙌

  • @nooneneedstoknow7
    @nooneneedstoknow7 2 года назад +1

    Understood!

  • @tejakumarreddyc2357
    @tejakumarreddyc2357 2 года назад +2

    in order to traverse in the first row, column and last row, column
    we can use this ( rows & columns will have index either 0 or m-1 or n-1)
    for(int i =0; i < n ; i++)
    {
    for(int j = 0 ; j < m; j++)
    {
    if((i == 0 || j == 0 || i == n-1 || j == m-1)&&
    mat[i][j] == 'O' && vis[i][j]==0)
    {
    dfs(i,j, mat , vis,result);
    }
    }
    }

    • @ishanupadhyay5351
      @ishanupadhyay5351 2 года назад +2

      It has m*n complexity, our solution has m+n complexity

  • @aryashjain7893
    @aryashjain7893 2 года назад

    understood , thnk u striver

  • @suryakiran2970
    @suryakiran2970 Год назад

    Understood❤

  • @udaypratapsingh8923
    @udaypratapsingh8923 2 года назад

    here we go !

  • @shriyanshjain4444
    @shriyanshjain4444 Год назад +5

    Solved it without starting the video
    Thank you Raj bhaiya for this wonderful playlist!
    CODE:
    class Solution {
    private:
    int dir[5] = {0,-1,0,1,0};
    void bfs(int r, int c, vector &board, vector &safe){
    safe[r][c] = true;
    queue q;
    q.push({r,c});
    while(!q.empty()){
    int row = q.front().first;
    int col= q.front().second;
    q.pop();
    for(int i = 0; i < 4; ++i){
    int nrow = row + dir[i], ncol = col + dir[i+1];
    if(nrow >= 0 && ncol >= 0 && nrow < board.size() && ncol < board[0].size() && board[nrow][ncol] != 'X' && !safe[nrow][ncol]){
    safe[nrow][ncol] = true;
    q.push({nrow,ncol});
    }
    }
    }
    }
    public:
    void solve(vector& board) {
    int m = board.size(), n = board[0].size();
    vector safe(m,vector(n,false));
    for(int i = 0; i < m; ++i){
    for(int j= 0; j < n; ++j){
    if(i == 0 || j == 0 || i == m-1 || j == n-1){
    if(board[i][j] != 'X' && !safe[i][j]){
    bfs(i,j,board,safe);
    }
    }
    }
    }
    for(int i =0; i < m ; ++i){
    for(int j = 0; j < n; ++j){
    if(board[i][j] != 'X' && safe[i][j] == true){
    continue;
    }else{
    board[i][j] = 'X';
    }
    }
    }
    }
    };

    • @flsh1343
      @flsh1343 Год назад

      Hello, I also tried to solve without watching this video. Can you help me with this code, why it got stuck at 41/58 TC on leetcode :-
      class Solution {
      public:
      void solve(vector& board)
      {
      int n = board.size();
      int m = board[0].size();
      vector visited(n, vector (m,0));
      vector temp(n, vector (m,'X'));
      queue q;
      for(int i = 0; i

    • @krishgupta4408
      @krishgupta4408 Год назад

      @@flsh1343 class Solution {
      public:
      void solve(vector& board) {
      int n = board.size();
      int m = board[0].size();
      vector visited(n, vector (m,0));
      vector temp(n, vector (m,'X'));
      queue q;
      for(int i = 0; i

  • @jambajuice07
    @jambajuice07 Год назад

    loving it

  • @mriduljain6809
    @mriduljain6809 Год назад

    Understood Bhaiya

  • @cinime
    @cinime 2 года назад +1

    Understood! Is this how to fill by one color in an area surrounded by different color? Anyway, so amazing explanation as always, thank you very much!!

  • @beinghappy9223
    @beinghappy9223 2 года назад

    Just Wow observation

  • @_hulk748
    @_hulk748 Год назад

    thankyou sir 🙇‍♂❤🙏 understood

  • @p38_amankuldeep75
    @p38_amankuldeep75 2 года назад

    understood💙💙💙

  • @SuryajyotiDas
    @SuryajyotiDas 2 года назад

    thank you bhai💝

  • @DanielAmoateng-q8k
    @DanielAmoateng-q8k Год назад

    Thank you!

  • @thetruth4461
    @thetruth4461 2 года назад

    Understood thank you sir

  • @VishnuKumar-ig4rt
    @VishnuKumar-ig4rt Год назад

    Thanks striver

  • @The_Shubham_Soni
    @The_Shubham_Soni Год назад

    UNDERSTOOD.

  • @bharathreddy3847
    @bharathreddy3847 2 года назад +1

    thank you bro

  • @Learnprogramming-q7f
    @Learnprogramming-q7f 8 месяцев назад

    Thank you Bhaiya