Number of Islands - Leetcode 200

preview_player
Показать описание
Number of Islands - Leetcode 200
Рекомендации по теме
Комментарии
Автор

Learn Data Structures & Algorithms for FREE at AlgoMap.io!

GregHogg
Автор

When I helped a senior engineer interview some candidates, he always asked this question.

davidshipman
Автор

I literally just solved this
But this method is much more efficient
Thanks again Greg 😊

Matrixerqwerty
Автор

Uncle, you're video helped me a lot. Thanks ya❤

samarth
Автор

This problem was in a codeforces contest too

ceciljoel
Автор

Can I… approximate? With something like a kernel convolution as the basis for finding edges?

blazingazong
Автор

haha i had to do this in a game to make sure the player only built one "island" perse, i just rawdogged the search algorithm and it turns out to work.

beaf
Автор

Fuzz buzz is the most asked question in interviews

Sluggernaut
Автор

I remember back in the day I was optimizing a connected component clustering algoritm and tried to get labs from a connectivity matrix as fast as possible. I faintly remember that the best solution was to do a QR decomposition of the matrix. However, I did it in Matlab there was some speciality that it returned some row order array which was what I was looking for right away. Some day I should try to recreate my code and probably have a lool at Lapack and see what was actually going on :D

Chronologist
Автор

Very fun problem, one of my favorite dfs questions

eric
Автор

I think this can be solved very similarly to 'bwlabel' in MATALB - using the Two - Pass algorithm. On the first pass label every 1 and write down equivalencies, then on the second pass just relabel according to the equivalencies.

neevpenkar
Автор

wouldn't disjoint sets be better?

kho-uw
Автор

I was going to do it differently,
Make a counter set to 0, loop over each element, if 1, check (i-1, j) == 1or (i, j-1) == 1, if not, add to counter, if yes, skip

luan
Автор

And to use O(1) memory you can write 2 instead of 1 for the islands. Now you know what vertices you already visited.

spacey
Автор

You reversed row and column, rows are horizontal.

Karthikeya.A
Автор

Why do you say there are three islands here if there is only one island?

егор-шоз
Автор

What's the answer?!? Haha you could have posted it for a blip so i could look over the code! I'm not even sure you can solve it based on this video, so today, I will not be purchasing or looking at your videos.

lbozbabyjsus
Автор

Given the explanation, there's really only ONE island.

mhalton
Автор

Yeah but in case of
[1, 1, 0]
[1, 0, 0]
What do those 1's make? Gotta be more specific on the conditions.

shirakuyanai
Автор

Solution :-



print("total islands = 3"). 😂

ujjwalaggarwal
join shbcf.ru