G-8. Number of Islands | Number of Connected Components in Matrix | C++ | Java

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

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

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

    In leetcode, the question is different. Read the movements there.
    Let's continue the habit of commenting “understood” if you got the entire video.
    Do follow me on Instagram: striver_79

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

      Striver, video description me " C++/Java/Codes and Notes Link" galat hai...

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

      @@venkatesh.guntreddi i would say learn basics of loop ,for ,if else statement first and then move in to advance topices like stack ,queue etc . all the best and welcome to the coding community my brother

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

      yes , only four diresctions are considered in it .

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

      Understood

    • @PriyankaGupta-nb6wl
      @PriyankaGupta-nb6wl Год назад

      yes, leetcode question is bit different, instead of 8 directions, 4 are considered.
      its code can be
      class Solution {
      public:
      void bfs(vector&vis,vector&grid,int i,int j)
      {
      vis[i][j]=1;
      int n=grid.size();
      int m=grid[0].size();
      queueq;
      q.push({i,j});
      while(!q.empty())
      {
      int row=q.front().first;
      int col=q.front().second;
      q.pop();
      /This part has to be changed
      int nrow=row-1;
      int ncol=col;
      if(ncol>=0 && ncol=0 && nrow=0 && ncol=0 && nrow=0 && ncol=0 && nrow=0 && ncol=0 && nrow

  • @sadiashafaque3517
    @sadiashafaque3517 Год назад +41

    This is by far the best graph series ever found on internet, cant thank you enough for this!

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

      for graph check out Luv graph series

  • @theskyspace8280
    @theskyspace8280 Год назад +15

    I've been hoping from few playlists and books lately to get some confidence in this topic and your series just does that.
    Thanks tons.

  • @rahulreddyambati9065
    @rahulreddyambati9065 3 месяца назад +6

    Striver, I Thank You a lot ! I just had a similar question in which this was a part in my GOOGLE interview. Couldn't have done it without this. Thanks again :)

  • @___divykant___
    @___divykant___ Год назад +8

    you appplied the same for loops in 3D DP - when ALICE and BOB wanted to collect the choclates , just amazing how you teach and how we corelate ❤❤

  • @rahulyadavKEC
    @rahulyadavKEC Год назад +31

    For leetcode Problem... small change in the condition for the directions...
    class Solution {
    private:
    void bfs(vector& grid,int i,int j,vector&vis)
    {
    vis[i][j]=1;
    queueq;
    q.push({i,j});
    int row=grid.size();
    int col=grid[0].size();
    int delrow[4]={-1,0,1,0};
    int delcol[4]={0,1,0,-1};
    while(!q.empty())
    {
    int r=q.front().first;
    int c=q.front().second;
    q.pop();
    for(int k=0;k=0 && newrow=0 && newcol

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

    adding a pseudo code for four directional traversal namely up, down ,left and right.
    vector delta = {0,1,0,-1,0};
    for(int k =0;k

  • @nathonluke4058
    @nathonluke4058 2 года назад +24

    Amazing 😍😍, I did it with DFS. But i have a small doubt. In numIsland function where you are first time calling the BFS first time. Can we put the grid [i][j] =='1' This would decrease the number of BFS calls? ..
    Edit: You already Corrected that😎😎.... Means i am on right path🔥🔥🔥

  • @UECSoumyaRay
    @UECSoumyaRay Год назад +63

    The LeetCode and the GFG problem are vastly different. For starters, the LeetCode problem is only 4 dimensional and the GFG one is 8 dimensional(which is not a big deal, ofc). But the LeetCode problem has the concept of rotation which is different from the GFG problem. LeetCode problem is based on identification of "identical islands". GFG problem deals with identification of "connected islands"

    • @sahilbani7020
      @sahilbani7020 Год назад +10

      thanks mate, I didn't read the leetcode problem
      there's a simple change to the if condition
      if(delrow==0 || delcol==0)

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

      @@sahilbani7020 thanks bhai

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

      Yes in leetcode u need to add the condition of abs value of i == abs j then continue it like that ...

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

      bro its now in premium category...sad me

    • @vinaykumardiona
      @vinaykumardiona 9 месяцев назад

      bro i wasted lot of time because of this bro. thank you so much...

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

    Space complexity for queue will be O(max(M,N))
    since bfs is a level order traversal and we start from the first most element, the maxm num elements will be the diagonal

  • @adityasood04
    @adityasood04 3 месяца назад +9

    For people who are confused in Leetcode problem:
    In leetcode, it is specified that we have to check only in 4 direction instead of 8 i.e. top, right, bottom and left.
    The same code will work, just you have to not consider the remaining 4 directions.
    You have to add this extra check in your loops:
    if((i==-1 && j==-1) || (i==-1&&j==1) || (i==1&&j==-1) || (i==1&&j==1)) continue;
    Updated for loops in bfs() function:
    for(int i=-1; i=0 && nbrCol < m && grid[nbrRow][nbrCol] == '1' && !vis[nbrRow][nbrCol]){
    vis[nbrRow][nbrCol] = 1;
    q.push({nbrRow, nbrCol});
    }
    }
    }

    • @nishantg7840
      @nishantg7840 3 месяца назад +1

      if((i==-1 && j==-1) || (i==-1&&j==1) || (i==1&&j==-1) || (i==1&&j==1)) continue;
      instead we can write if(i*j!=0) continue;

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

    Such a great explanation dada... for such a complex question ... took around 2 hrs to understand and code it down... but very well and clear explanation

  • @unknown2003august
    @unknown2003august 4 месяца назад +1

    understood so well , that even i can teach it anybody with full confidence , Thankyou Striver 😇

  • @Zomb-zj4ip
    @Zomb-zj4ip 5 месяцев назад

    for current leetcode question, an isalnd is considered as connected only through horizontal and vertical connections. to tackle this, simply skip the diagonal traversals while checking neighbours. to do this, inside the double nested for loop traversing delrow anddel col. include the first line as
    if(adjrow!=0 && adjcol!=0) continue;
    rest all remains exactly same.

  • @Ace-ex9gg
    @Ace-ex9gg Год назад +9

    you made java code a little complicated because i implemented in dfs and was way easier to understand. but anyway the explaination was realy good

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

    took two days but in the end "UNDERSTOOD" Thank U striver

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

      @@udaypratapsingh8923 not every one is smart as u

  • @nandiniverma5273
    @nandiniverma5273 2 года назад +10

    Thankyou soo much for deep explanation and also for providing code in java , it really helps

  • @mehulpathak9845
    @mehulpathak9845 4 месяца назад +1

    Finally understood this problem completely . Thanks Striver.

  • @AtharvaRao0104
    @AtharvaRao0104 Месяц назад

    This grid can also be converted into a graph of adjacency list. But it may be time consuming in an interview. To do this, consider each box on the grid as a node. we need to number the nodes.
    So in above we can observe node 1 is connected to node 2, node 5, node6 . Node 0 and Node 1 are not connected. Node 0 and Node4 are also not connected. and so on ..
    But Grid problems are solved faster using the direction vectors to get the neighbours and referring to the node as a pair as shown in the video..
    Please watch William Fiset video on graph playlist related to grid. He has explained wonderfully.

  • @the_humble_lazy
    @the_humble_lazy 7 месяцев назад +2

    the shortcut for visiting all the nodes was awesome

  • @shashank4577
    @shashank4577 2 года назад +26

    Instead of creating another 2d array as visited, we can just mark the visited ones in the given array as 2. Or any number other than 1. Will save space :P . Just my 2 cents.

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

      can you share your code's link?

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

      We don't want to change the original matrix so we have to use extra matrix and see space is same as if we are doing dfs then stack space, or if we are doing via bfs then queue space..

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

      Bro, saving space should be in the algorithm, not that you change the input data structures, they're just meant to provide you the input...

    • @factsspitter7360
      @factsspitter7360 Год назад +6

      It's a bad practice and cheating as some interviews might not allow you to modify inputs.

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

      People say we should never modify the inputs

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

    I m touched as well with the dedication, you teach selflessly. ❤
    You are gem bro..

  • @ayushanand18
    @ayushanand18 Год назад +2

    I really like his videos for the way he discusses time complexity.

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

    It is similar ques to the previous one , where we calculated the proviences, but the diff is here we are working with matrix

    • @AtharvaRao0104
      @AtharvaRao0104 Месяц назад

      no they are not similar. Province problem was graph represented in a matrix. A grid is different from a matrix. In a grid each box is a node. where as in a matrix representation each row is associated with the node and tells which other nodes this node connects to..

  • @a-talks4197
    @a-talks4197 2 года назад +4

    Understood !! how easily you let us understand so much hard questions in a very easy manner :)

  • @player-te8tf
    @player-te8tf 2 года назад +24

    For the people suffering on leetcode, take a check just after that shortcut trick so that we dont check the diagonal elements as connected components -
    void bfs(int row,int col, vector &vis, vector &grid){
    vis[row][col]=1;
    queue q;
    int n = grid.size();
    int m = grid[0].size();
    q.push({row,col});
    while(!q.empty()){
    int row = q.front().first;
    int col = q.front().second;
    q.pop();
    //for neighbouring elements or cell.
    //you could use direct indexes too :)
    for(int del_row=-1;del_row

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

      Thanks !)

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

      Thanks

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

      Thanks :-)

    • @jonny._.1313
      @jonny._.1313 2 года назад +1

      Intuition behind this shortcut please which is used to check all connected lands

    • @player-te8tf
      @player-te8tf 2 года назад +2

      @@jonny._.1313evenif i will be explaining then it wont get clear to u untill u dry run the shortcut code itself......anyways...... But, you could even do it directly using indexes.

  • @VikashKumardhor
    @VikashKumardhor 4 месяца назад +1

    instead of using visited matrix we can directly put replace that 1 with 0 reducing the space complexity

  • @stith_pragya
    @stith_pragya 6 месяцев назад +1

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

  • @aniketjain6886
    @aniketjain6886 Месяц назад

    Beautifully explained 🎉❤❤❤

  • @YashJoshi-lt4gd
    @YashJoshi-lt4gd 29 дней назад

    He says" I am touched" :))) wonderful explanation..

  • @LightYagami406
    @LightYagami406 4 месяца назад +1

    for LeetCode the solution is slightly different since it only allows movement in 4 directions only
    The DFS code is as follows:
    class Solution {
    public:
    void dfs(int row, int col, vector&grid, vector &vis){
    int n = grid.size();
    int m = grid[0].size();
    vis[row][col] = 1;
    int delR[4]= {-1,0,1,0};
    int delC[4]= {0,1,0,-1};
    for(int i =0; i=0 && nRow=0 && nCol

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

    Understood! Super great explanation as always, thank you very much!!

  • @LeylaLi-v4w
    @LeylaLi-v4w Год назад +1

    I love this video! It's very clear and easy to follow. Thank you!!

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

    Again I solved this problem by myself only after watching your explanation, Thank you striver for this amazing video 😁

  • @shrutichouksey1324
    @shrutichouksey1324 4 месяца назад +1

    Thank you so much bhaiya for this series

  • @NARUTOUZUMAKI-bk4nx
    @NARUTOUZUMAKI-bk4nx 10 месяцев назад +1

    Understood
    For leetcode problem only made this change
    for(int delrow=-1;delrow

  • @artofwrick
    @artofwrick 9 месяцев назад

    We might store the movements in two individual arrays for row and column. And then we may do it.

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

    Question in leetcode and GFG has different neighbor conditions, thanks that I'm able to solve both

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

    The exact solution in python "TLE"s (10/26) 😵
    Welp, have to embrace the pain of coding in Python.
    Anyways, great to learn something new. Thanks!

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

    Amazing your vedio question always on leectode and which helps to make profile amazing soo much thank you sir

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

    Liked the video, notes taken, understood

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

    Best explaination so far. Appreciate it!
    Thanks

  • @isheep9025
    @isheep9025 Год назад +9

    Leet code c++ solution:
    class Solution {
    public:
    void solver(int i,int j,vector & grid,vector & visited)
    {
    int n=grid.size();
    int m=grid[0].size();
    queue q;
    q.push({i,j});
    visited[i][j]=1;
    while(!q.empty())
    {
    auto p=q.front();
    int row=p.first;
    int col=p.second;
    q.pop();
    int nr=row+1;
    int nc=col+0;
    if((nr>=0 && nr=0 && nc=0 && nr=0 && nc=0 && nr=0 && nc=0 && nr=0 && nc

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

      you are repeating the code instead use a function to check for adjacent "1".

  • @Mohit-mc6us
    @Mohit-mc6us 5 месяцев назад

    00:08 Number of islands in a grid
    02:19 You can achieve complete coverage of the connected nodes by performing three traversals.
    04:34 Three islands exist
    06:56 We are using adjacency list to find neighbors
    09:18 BFS traversal starting points
    11:36 The code describes the implementation of a BFS traversal for a character grid
    13:38 Implement BFS algorithm to mark cells in a grid
    15:47 Learn a shortcut to find the neighbors of a given location on a grid
    17:59 You can easily get all the neighbors using the given technique.
    19:58 Use BFS algorithm with a matrix to solve a particular problem.
    22:00 The space complexity is approximately O(n^2) and the time complexity is approximately O(n^2)
    23:45 The time complexity is roughly n square.

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

    We can also define vector direction = [{0,1},{1,0},{0,-1},{-1,0},{-1,-1},{1,-1},{1,1},{-1,1}] then traverse using
    for(auto adj: direction){
    n_ row = row+adj.first;
    n_col = col +adj.second;
    }
    To get the all the neighbor of (row,col);
    Thanks Striver :)

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

    understood 😀and wow i learn new techniques for visiting all neighbours

  • @aditya_raj7827
    @aditya_raj7827 9 месяцев назад +1

    Understood 😊

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

    understood!!! learnt new trick for finding neighbours
    i first tried it in iterative way then wathed the video

  • @VikasBagri-i5j
    @VikasBagri-i5j 3 месяца назад

    understood.. thanks for this amazing series :)

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

    was a challenging one, also very well explained!!

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

    Understood. Thank you.

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

    Understood 🙏

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

    Understood 😎

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

    understood

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

    Understood. Thank you so much.

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

    Thank you sir 😊

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

    Understood!! Awesome Explanation...

  • @jaishriharivishnu
    @jaishriharivishnu 4 месяца назад

    kya baat hai boss, ekdum faadu

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

    Thank you, Striver. Understood.

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

    Easy and Shortest one for this..........
    void DFS(vector& grid, int i, int j) {
    // boundary checking
    if(i < 0 || i >= grid.size() || j < 0 || j >= grid[0].size())
    return;
    // return if current position is of water or is already visited
    if(grid[i][j] == '2' || grid[i][j] == '0')
    return;
    // mark the current as visited
    grid[i][j] = '2';
    // do DFS in all 4 directions
    DFS(grid, i+1, j);
    DFS(grid, i, j-1);
    DFS(grid, i-1, j);
    DFS(grid, i, j+1);
    }
    int numIslands(vector& grid) {
    // We can treat the matrix grid as a grid. Each Island is a
    // connected component. The task is to find no. of disconnectedd components
    // in the graph.
    int islands = 0;
    // We make each 1 as 2 in when it is visited
    for(int i = 0; i < grid.size(); i++) {
    for(int j = 0; j < grid[0].size(); j++) {
    // do DFS in case has not been visited and there is land
    if(grid[i][j] == '1') {
    DFS(grid, i, j);
    ++islands;
    }
    }
    }
    return islands;
    }

  • @abhishekdash4933
    @abhishekdash4933 Год назад +2

    Hey @Striver, explanation is on point, realy helpful. One thing I noticed you explain the bfs storage to be a queue but u always represent on diagram a stack,
    As per my understanding in bfs we use queue FIFO and in DFS its stack LIFO. Feel free to correct if am wrong.

    • @SwatejTech
      @SwatejTech Год назад +4

      he only draws it like a stack but he removes from the bottom only, just like a queue

  • @googleit2490
    @googleit2490 11 месяцев назад +1

    Graph Revision:
    Done and dusted in Grarph Revision (DFS)
    (9 mins)
    Nov'24, 2023 10:58 pm

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

    abs(delrow - delcol) == 1 condition should be added

  • @YATHARTHBHARDWAJ-y8m
    @YATHARTHBHARDWAJ-y8m Год назад

    superb explanation

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

    btw understood and liked.Although please elaborate a little in depth on the TC and SC part atleast in the few videos.

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

      Since we are reading graphs, am assuming you are well versed with time complexity. If you are not, I think you should get those basics right before getting deep into graphs 😅

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

      @@takeUforward fair enough. Although I do have basic understanding but I always get lost for recursion cases. So does watching your first 7 videos from recursion playlist will do the trick for TC part?

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

      @@abhinavkumar6584 First 9 vidoes should be good.

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

      @@sonit9707 thanks..although I finished the playlist already...but thanks again for replying

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

    understood it very well...

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

    Completely UNDERSTOOD

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

    Thank you, Striver 🙂

  • @adebisisheriff159
    @adebisisheriff159 9 месяцев назад

    Thanks so much Striver!!!!

  • @KunalSingh-kn2ij
    @KunalSingh-kn2ij 2 года назад +1

    perfect explanation👍👍

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

    Thank you so much striver

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

    thanks brother for explain this question in very easy way thank you so much

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

    Thank you so much, it was superb

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

    Please also make articles for these questions on the website.

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

      In description there is a link

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

      @@takeUforward Yes, But that link in the description is for BFS traversal, not specifically for the "Number of islands" question.

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

    solved DFS of it's by OWN

  • @TarunKumarSaraswat
    @TarunKumarSaraswat Месяц назад

    Thanks

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

    Awesome explanation ... understood

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

    Loved your explanation😍😍😍😍

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

    Thankyou soo much for deep explanation

  • @KUMARSAURABH-s5i
    @KUMARSAURABH-s5i 5 месяцев назад

    Understood Striver!!

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

    Leetcode problem dont want to consider diagonal elements:
    so slight modify:
    for(int delrow = -1;delrow

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

    understood striver
    great explanation👍

  • @rawat_ji5183
    @rawat_ji5183 2 года назад +9

    I have done this dfs sol and feel very confident after the solution got submitted successfully thank you striver 😁😁
    void bfs(vector &value , vector&vis,int row,int col)
    {
    vis[row][col]=1;
    int r= value.size();
    int c= value[0].size();

    for(int i=-1;i

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

      you have written dfs code ,function is bfs ;)

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

      @@amitranjan6998 yaa my function name is bfs but code is dfs 😅😅😅😅

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

    Understood

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

    No one can explain this....as easy as you do....🥹

  • @SatyamKumar-bw4vi
    @SatyamKumar-bw4vi Год назад

    Jay Jagannath Striver..!
    I think we don't have to go all 8 direction only 4 direction is enough but very good video

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

    understood bhaiya

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

    We can also do it without using another visited array by changing in the same array.
    Your explanation quality is so smooth and fantastic. Thank You.
    void f(int i,int j,vector&grid)
    {
    if(i=grid[0].size() || grid[i][j]=='0') return;
    grid[i][j]='0';
    for(int dx=-1;dx

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

      Doing manipulation in the original data is not preferred and not allowed in industry.

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

    best explanation !

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

    understood ,great explanation

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

    Best series

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

    understood!! SIR

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

    How come the TC is 8XN^2. As you said the 9th Iteration will be ignored since it is already visited. The same will happen for the remanining nodes too. If that node is already visited we are not doing the work inside the nested loops for those nodes. So ultimately we will do work for only those nodes which are not visited.(Just like we ignore the 9th iteration since it is already visited, we ignore the remaning nodes too if already visited)> So the time complexity will be O(N^2) but not 8XN^2. Please correct me If I am wrong...:)

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

    Awesome explanation

  • @shubharthaksangharsha6248
    @shubharthaksangharsha6248 Год назад +4

    Bhaiya, Is it possible if we convert this adjacent matrix to list and then just apply the BFS/DFS and count the islands ?

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

      i don't think so because its not an adjacent matrix its a normal matrix .

    • @gorilla_coder-el6kf
      @gorilla_coder-el6kf Год назад

      no you can't here.because, here the indices don't represent nodes or vertices of graph .instead they are coordinates of each point.

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

    Understood Striver!

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

    Understood 💙. Bhaiya one suggestion. Don't display the Java code for a long time.. Keep it for 5 -10 seconds.

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

      Java walon ko dikkat hga bro. C++ wle ko issues nai hota utna

  • @deepak-ly3ob
    @deepak-ly3ob Год назад

    Thanks bhaiya

  • @01kumarr
    @01kumarr Год назад

    really u take me forward thanks a lot !

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

    As always you are a rock star ✨