question:-
Given a grid consisting of '0’s(Water) and '1’s(Land). Find the number of islands.
Note: An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically or diagonally i.e., in all 8 directions.
Input:
grid = {{0,1},{1,0},{1,1},{1,0}} **
Output:** 1 **
Explanation:** The grid is- 0 1 1 0 1 1 1 0 All lands are connected.
Seriously, I checked my contest history to see if I screwed some rated contest XD…
3 Likes
Hahaha… Saw you a few days back at Cladding the Code contest and as usual, just stalked you a bit and loved this avatar.
1 Like
in question they have mentioned all 8 directions
yeah bro got it
1 Like
thank you
1 Like
even I thought same
1 Like
@anon84382313 I read the problem statement, yes it requires the diagonal calls also. sorry, my bad. I thought neighbours are up, down, left and right only.
ps: removing the other solution
Correct approach :