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

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 พ.ย. 2024
  • GfG-Problem Link: bit.ly/3QyPr5g
    C++/Java/Codes and Notes Link: takeuforward.o...
    DP Series: • Striver's Dynamic Prog...
    SDE Sheet: takeuforward.o...
    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.geeks...
    Code "takeuforward" for 20% off on sys-design: get.interviewr...?_aff=takeuforward
    Crypto, I use the Wazirx app: wazirx.com/inv...
    Take 750 rs free Amazon Stock from me: indmoney.oneli...
    Earn 100 rs by making a Grow Account for investing: app.groww.in/v...
    Linkedin/Instagram/Telegram: linktr.ee/take...
    ---------------------------------------------------------------------------------------------------------------------------

ความคิดเห็น • 300

  • @takeUforward
    @takeUforward  2 ปีที่แล้ว +104

    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 2 หลายเดือนก่อน

      Understood Everything Thank you so Much

  • @shivyanshgarg2641
    @shivyanshgarg2641 11 หลายเดือนก่อน +33

    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

    • @shreyxnsh.14
      @shreyxnsh.14 15 วันที่ผ่านมา

      Same

    • @yush158
      @yush158 5 วันที่ผ่านมา

      Same

  • @anushkajain1843
    @anushkajain1843 ปีที่แล้ว +63

    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 9 หลายเดือนก่อน +5

    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 6 หลายเดือนก่อน

      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...

  • @HarshRaj-kk7rd
    @HarshRaj-kk7rd ปีที่แล้ว +13

    the energy you bring while teaching is just amazing

  • @sahilbani7020
    @sahilbani7020 6 หลายเดือนก่อน +4

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

  • @abdalla4425
    @abdalla4425 10 หลายเดือนก่อน +2

    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.

  • @tasneemayham974
    @tasneemayham974 9 หลายเดือนก่อน +1

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

  • @vadheraproductions1218
    @vadheraproductions1218 6 หลายเดือนก่อน

    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

  • @sonugupta147
    @sonugupta147 9 หลายเดือนก่อน +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.

  • @saurabhtiwari287
    @saurabhtiwari287 2 ปีที่แล้ว +4

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

  • @arunachalamm3399
    @arunachalamm3399 4 หลายเดือนก่อน

    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

  • @009_akshayrajput
    @009_akshayrajput ปีที่แล้ว +1

    "Understood", Marvelous explanation with high energy !!

  • @albatrossgeez6637
    @albatrossgeez6637 11 หลายเดือนก่อน +1

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

  • @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 ❤️

  • @vipulchaudhary_js
    @vipulchaudhary_js 2 ปีที่แล้ว +6

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

  • @kaimadamantonyshejin2034
    @kaimadamantonyshejin2034 ปีที่แล้ว +3

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

  • @Benstokes555
    @Benstokes555 7 หลายเดือนก่อน +1

    YOURE MY DIAMOND STRIVES :)

  • @juniorboy1903
    @juniorboy1903 2 ปีที่แล้ว +1

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

  • @ASHISHKUMAR-o4c6x
    @ASHISHKUMAR-o4c6x ปีที่แล้ว +1

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

  • @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

  • @sayandey2492
    @sayandey2492 ปีที่แล้ว +3

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

  • @roydebraj2188
    @roydebraj2188 4 หลายเดือนก่อน

    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

  • @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 :)

  • @1tav0
    @1tav0 2 ปีที่แล้ว +6

    Awesome, thank you striver as always understood

  • @VivekVerma-oo3dx
    @VivekVerma-oo3dx ปีที่แล้ว

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

  • @syedmohammadhussain7137
    @syedmohammadhussain7137 2 ปีที่แล้ว +1

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

  • @rohan8758
    @rohan8758 6 หลายเดือนก่อน +1

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

  • @HEMANTPORWAL-t7d
    @HEMANTPORWAL-t7d 6 หลายเดือนก่อน

    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

  • @stith_pragya
    @stith_pragya 11 หลายเดือนก่อน +1

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

  • @conceptualboy_vikash
    @conceptualboy_vikash ปีที่แล้ว

    kaya bat hai baiya ,maza aagya apka obserwation se

  • @DevashishJose
    @DevashishJose 10 หลายเดือนก่อน

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

  • @manojnavinjamuri5867
    @manojnavinjamuri5867 2 ปีที่แล้ว +3

    thank you striver for creating such amazing content

  • @ankitranjan88
    @ankitranjan88 ปีที่แล้ว +1

    Solved this one by self on BFS and DFS Both.

  • @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 😅

  • @rakshitharsh6169
    @rakshitharsh6169 ปีที่แล้ว +1

    excellent explanation!

  • @sakshisahu3983
    @sakshisahu3983 2 ปีที่แล้ว +1

    Thank you striver for all your efforts.

  • @shreyasinha4016
    @shreyasinha4016 หลายเดือนก่อน

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

  • @chandannikhil8526
    @chandannikhil8526 2 ปีที่แล้ว +2

    Understood bhaiya i have done bfs traversal

  • @varunaggarwal7126
    @varunaggarwal7126 ปีที่แล้ว +45

    I was so frustrated, I write '0' instead of 'O' and wondering why it is not working for 1 hour 🤦‍♂🤦‍♂

    • @anonymousanonymous7507
      @anonymousanonymous7507 11 หลายเดือนก่อน +1

      Good

    • @artofwrick
      @artofwrick 10 หลายเดือนก่อน +1

      I made a mistake in edge case, and spent 2 hours figuring where it went wrong. It took me the first hour just to merely accept that there was an error in the edge case

    • @akshayamarpu4956
      @akshayamarpu4956 5 หลายเดือนก่อน

      same dude

    • @KapilSharma56419
      @KapilSharma56419 4 หลายเดือนก่อน

      compilation error nhi kiya 0 int hai O char hai

    • @ooofrg4492
      @ooofrg4492 4 หลายเดือนก่อน

      Shabash❤😂

  • @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.

  • @harleenkaur7751
    @harleenkaur7751 2 ปีที่แล้ว +1

    Thanks a lotttt striver for such an amazing playlist

  • @developer00007
    @developer00007 6 หลายเดือนก่อน +1

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

  • @susanthomas223
    @susanthomas223 9 หลายเดือนก่อน

    Thank you so much for such a detailed video

  • @goatwice
    @goatwice 4 หลายเดือนก่อน +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

  • @harshvardhansingh2272
    @harshvardhansingh2272 2 ปีที่แล้ว +1

    understood striver
    Awesome explanation as always

  • @RajeshKumar._.16
    @RajeshKumar._.16 ปีที่แล้ว

    very nice approach and explanation

  • @kaichang8186
    @kaichang8186 2 หลายเดือนก่อน

    understood, thanks for the effort on the great video

  • @subhamoybera6456
    @subhamoybera6456 ปีที่แล้ว +1

    Great explanation 👍

  • @champion5946
    @champion5946 ปีที่แล้ว +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
    }
    }
    }

  • @sripriyapotnuru5839
    @sripriyapotnuru5839 2 ปีที่แล้ว

    Thank you, Striver 🙂

  • @Sumeet_100
    @Sumeet_100 ปีที่แล้ว

    Thank You striver Bhaiya 🤟

  • @vatsalvasoya5243
    @vatsalvasoya5243 ปีที่แล้ว

    Understood!! Very well explained!!!

  • @codewithom11
    @codewithom11 ปีที่แล้ว +1

    Majaa Aagaya😜

  • @pulkitchausali1354
    @pulkitchausali1354 ปีที่แล้ว +1

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

  • @RohitKumar-dz8dh
    @RohitKumar-dz8dh ปีที่แล้ว +1

    Understood 😊

  • @rishucs3240
    @rishucs3240 ปีที่แล้ว +1

    understood very well!!!

  • @vakhariyajay2224
    @vakhariyajay2224 ปีที่แล้ว

    Thank you very much. You are a genius.

  • @rishabhagarwal8049
    @rishabhagarwal8049 2 ปีที่แล้ว

    Understood Sir, Thank you very much

  • @kshithi2864
    @kshithi2864 2 ปีที่แล้ว

    Understood😁Thanks a lot Striver😃

  • @dharsan.s7937
    @dharsan.s7937 2 ปีที่แล้ว +1

    Legend is back

  • @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

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

  • @Learnprogramming-q7f
    @Learnprogramming-q7f 7 หลายเดือนก่อน

    Thank you Bhaiya

  • @viholvishwassinh1709
    @viholvishwassinh1709 หลายเดือนก่อน +1

    khatarnak insted of finding who will be mark as 'X' we will find whol will not such a great idea

  • @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

  • @gautamsaxena4647
    @gautamsaxena4647 6 หลายเดือนก่อน

    understood bhaiya

  • @gunahawk6893
    @gunahawk6893 ปีที่แล้ว

    just watched 1 min and solved the whole problem damn

  • @mriduljain6809
    @mriduljain6809 ปีที่แล้ว

    Understood Bhaiya

  • @albatrossgeez6637
    @albatrossgeez6637 11 หลายเดือนก่อน

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

  • @pogpieunited3379
    @pogpieunited3379 6 หลายเดือนก่อน

    understood paaji

  • @rudranshagg2580
    @rudranshagg2580 8 หลายเดือนก่อน

    BFS version of the logic (With comments 🚀🌟):
    class Solution {
    public:
    void solve(vector& board) {
    // I did using BFS. Can do it with DFS as well.

    // if an 'O' will be on the edge of the board we will not flip it
    // Start from the O's which are present on the boundary and find all the
    // O's that are connected to the boundary O's , these all O's will not
    // be converted , and all the other O's will be converted
    // have a visited vector ..yes to avoid going back to the parent indexes
    // (i,j)??
    queue q;
    int r = board.size();
    int c = board[0].size();
    vector vis(r, vector(c, 0));
    for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
    if (i == 0 || j == 0 || i == r - 1 || j == c - 1) {
    if (board[i][j] == 'O') {
    // shows this can't be fliped
    board[i][j] = '9';
    cout

  • @suhaanbhandary4009
    @suhaanbhandary4009 ปีที่แล้ว

    understood, thanks for such playlist!!

  • @CodeMode9313
    @CodeMode9313 ปีที่แล้ว

    ek dum mast

  • @RohitSharma-yc8lm
    @RohitSharma-yc8lm 2 ปีที่แล้ว +1

    #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

  • @mananarora141
    @mananarora141 ปีที่แล้ว

    UNDERSTOOD!!!!!!!!

  • @UECAshutoshKumar
    @UECAshutoshKumar ปีที่แล้ว +1

    Thank you sir

  • @suryanshsingh6423
    @suryanshsingh6423 5 หลายเดือนก่อน

    God of dsa🙏

  • @udaypratapsingh8923
    @udaypratapsingh8923 2 ปีที่แล้ว

    here we go !

  • @mihirsaini592
    @mihirsaini592 2 ปีที่แล้ว

    Great intuition

  • @parshchoradia9909
    @parshchoradia9909 ปีที่แล้ว

    Understood Sir!

  • @_sf_editz1870
    @_sf_editz1870 3 หลายเดือนก่อน

    A little readable java code may be : )) class Solution {
    public void solve(char[][] board) {
    //here the boundary zeros cant be converted so we just mark as x and their connectivity
    //after the connectivities are done from boundaries
    //we need to check like if its a 'O' and not visited from boundary then it definetly is surrounded by x's so we can make it as x
    int visited[][] = new int[board.length][board[0].length];
    //first row and first col checking for '0s'
    for(int i=0; i

  • @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!!

  • @The_Shubham_Soni
    @The_Shubham_Soni ปีที่แล้ว

    UNDERSTOOD.

  • @gangsta_coder_12
    @gangsta_coder_12 2 ปีที่แล้ว +1

    Understood 😀😀

  • @beinghappy9223
    @beinghappy9223 ปีที่แล้ว

    Just Wow observation

  • @per.seus._
    @per.seus._ 10 หลายเดือนก่อน

    UNDERSTOOD

  • @VishnuKumar-ig4rt
    @VishnuKumar-ig4rt ปีที่แล้ว

    Thanks striver

  • @visheshagrawal8676
    @visheshagrawal8676 ปีที่แล้ว

    solved without even looking solution that's the power of striver

  • @sukuna905
    @sukuna905 8 หลายเดือนก่อน

    understood sir

  • @nooneneedstoknow7
    @nooneneedstoknow7 2 ปีที่แล้ว +1

    Understood!

  • @thetruth4461
    @thetruth4461 ปีที่แล้ว

    Understood thank you sir

  • @aparna5364
    @aparna5364 2 ปีที่แล้ว +1

    Understood 🙂

  • @sukhpreetsingh5200
    @sukhpreetsingh5200 2 ปีที่แล้ว +1

    reached here
    😀

  • @amandubey5287
    @amandubey5287 ปีที่แล้ว

    Thank you so much for this. it was helful

  • @studyonline3236
    @studyonline3236 ปีที่แล้ว

    Thanks you very much bro for the series

  • @aryashjain7893
    @aryashjain7893 2 ปีที่แล้ว

    understood , thnk u striver

  • @fadebeyond
    @fadebeyond 2 ปีที่แล้ว +1

    understood