Number of islands | Leetcode #200

preview_player
Показать описание
This video lecture explains a very important interview programming question which is to find number of islands on a matrix or grid. This is same as finding the number of clusters on a graph or matrix or grid. This is a typical DFS or BFS problem under graph algorithms. This can also be solved using Disjoint Set. I have explained the DFS approach for this problem using examples and code explanation. As usual, CODE LINK is given below. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)

Рекомендации по теме
Комментарии
Автор

I don't know how to thank you . We are paying money in lacs to college still they don't teach anything. But you are giving us these amazing explanation for free. Thank you so much brother. Keep making videos

akshatjain
Автор

Your way of solving problems is easy to understand .. thank you for such a nice contents.

gauravsrivastavjsr
Автор

I went over leetcode explanation, did not get it. Then i went over few of you tube videos where they just solved the question giving minimal explanation. Then i bumped on this. Thank you so much brother. I was trying to understand DFS practically and this pretty much sums it out for a beginner like me. Thanks a bunch again.

HarkiratSaluja
Автор

This is good explanation, suppose if going diagonally is also allowed . then will this work if we just add these 4 more directions to the existing 4 directions

mark_current_island(matrix, x-1, y-1, r, c); // LEFT UP DIAGONAL
mark_current_island(matrix, x-1, y+1, r, c); //RIGHT
UP DIAGONAL
mark_current_island(matrix, x+1, y-1, r, c); //LEFT DOWN DIAGONAL
mark_current_island(matrix, x+1, y+1, r, c); //RIGHT
DOWN DIAGONAL

AruneshSrivastava
Автор

You explain way better than some youtubers with thousands subs. Thank you, dude! Keep doing

beketmyrzanov
Автор

That's an extraordinary explanation mate. You made it look so simple. Thanks a lot.

shritishaw
Автор

Great solution, and using the graph itself to store the visited state is a big brain move.

redleader
Автор

I think the time complexity should be O(n * m) as we are traversing the whole matrix

hemantsood
Автор

good explanation, found a Indian programming tutorial gem :).

QuantumTick
Автор

dude, you are the best teacher out there!!. Can call you as "Teacher" with out any spelling mistake!!

stupify
Автор

thank you so much! I love your teaching style. Although many YouTubers did algorithm videos, some of them started coding at first without exquisite explanations, so I can't follow them. Thank you again bro.

luobohu
Автор

There are so many videos on youtube for this problem. Your explanation is the best 🍻

spetsnaz_
Автор

awesome bro...
Another method I thought was to first find the indices of all the 1's and store it in list l.
Then traverse through the list in dfs and keep on removing the elements from the list l if found ...
But 😅one of the test case went out of time...46/47.

saurabhsengar
Автор

Literally u made be this question a cake walk for me . Never studied DFS but your Clear voice filled with knowledge taught me everything

devesh
Автор

i recently started watching referring your videos. This one is amazing. Such a clear and neat explanation! Thank you for this.

radhu
Автор

Thanks, TechDOSE for this amazing graph series...thanks a lot...

ritikbhardwaj
Автор

please make video on other graph algorithm.. your way of writing code and explaining is crystal clear.

shishpalvishnoi
Автор

it was literally a crystal clear explanation for this question
thanku TechDose
u just made my

snehasoni
Автор

Waiting for disjoint set implementation of the above problem.
Btw Nice explanation! Thank you!!

SajidAli-ubth
Автор

Thank you for this crystal clear explanation! I could not follow other explanations found on the internet, but this was very clear.

davidalexander