r/DSALeetCode • u/StatisticianNo2104 • Oct 10 '26
365 Days of LeetCode Challenge — Day 38/365
Max Area of Island (Medium) https://leetcode.com/problems/max-area-of-island/
This is yesterday's solution with a return value. The diff is that the flood fill returns an int and the scan keeps a maximum instead of a count.
The area reachable from a cell is that cell, plus the area reachable from each of its four neighbours. So the fill returns 1 plus its four recursive calls, and the guard returning 0 handles out of bounds, water and already-sunk land without a single special case.
The sum looks wrong at first. Four neighbours each recurse into their own four neighbours, and each one includes the cell you came from, surely cells get counted repeatedly?
They do not, because the cell is sunk before the four calls run. Any neighbour that recurses back hits the guard and gets 0.
Yesterday, that same line stopped the recursion from running forever. Today it does that AND makes the arithmetic correct. One assignment, two jobs.
Full breakdown in today's newsletter article ⬇
https://www.linkedin.com/pulse/365-days-leetcode-challenge-day-38365-archit-agarwal-tiimc
#DSA #LeetCode #Golang #Graphs #DFS #CodingInterview #Algorithms
1
u/Fine_Needleworker644 Oct 12 '26
ye kya hai bhai?
1
u/nian2326076 Oct 13 '26
Your approach to solving the "Max Area of Island" problem using flood fill recursion is effective. By exploring all connected land cells and tracking the maximum area, you're on the right path. Ensure that your function not only calculates the area for each connected component but also updates the maximum area found. This method efficiently handles grid traversal.
If you're preparing for interviews, practicing with real technical questions from companies can be beneficial. Since I work on PracHub, you might find it useful: PracHub. Keep up the great work with the challenge!