PYTHON 3 | EASY SOLUTION
The function then defines an inner function called dfs that performs a depth-first search on the grid starting from a given position (i,j) and returns the sum o
The function then defines an inner function called **dfs** that performs a depth-first search on the grid starting from a given position (i,j) and returns the sum of fish in the connected region.\n\nThe dfs function first checks if the **current** position is **outside the bounds** of the grid or if the position corresponds to a cell with value **0 or -1** (0 - water, -1 - visited). If any of these conditions is true, the function returns 0 (**no fish here**).\nOtherwise, the function retrieves the number of fish fish in the current cell, sets the cell value to -1 (*to mark it as visited*), and recursively calls itself on the four adjacent cells (up, left, down, and right), accumulating the fish counts in a variable temp.\n\n```\n    def findMaxFish(self, grid: List[List[int]]) -> int:\n        N, M = len(grid), len(grid[0])\n        \n        def dfs(i, j, temp):\n            if i < 0 or j < 0 or i >= N or j >= M or grid[i][j] in [0, -1]:\n                return 0\n            \n            fish = grid[i][j]\n            grid[i][j] = -1  # visited\n            temp += (fish + dfs(i-1, j, temp) + dfs(i, j-1, temp) + dfs(i+1, j, temp) + dfs(i, j+1, temp))\n\n            return temp \n        \n        maxi = 0\n        for i in range(N):\n            for j in range(M):\n                if grid[i][j] > 0:\n                    maxi = max(maxi, dfs(i, j, 0))\n                \n        return maxi\n```
['Depth-First Search', 'Python3']