Easy DFS || Beats 70% || Java
Complexity\n- Time complexity: O(nm)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(nm) , stack space.\n Add your space complexity here, e
# Complexity\n- Time complexity: $$O(n*m)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n*m)$$ , stack space.\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    private final List<Integer[]> directions = List.of(\n            new Integer[]{1, 0}, new Integer[]{-1, 0}, new Integer[]{0, 1}, new Integer[]{0, -1}\n    );\n\n    public int findMaxFish(int[][] grid) {\n        int maxFish = 0;\n        for (int i = 0; i < grid.length; i++) {\n            for (int j = 0; j < grid[0].length; j++) {\n                if (grid[i][j] != 0) maxFish = Math.max(maxFish, dfs(i, j, grid));\n            }\n        }\n        return maxFish;\n    }\n\n    private int dfs(int i, int j, int[][] grid) {\n        if (notValid(i, j, grid) || grid[i][j] == 0) return 0;\n        int fish = grid[i][j];\n        grid[i][j] = 0;\n        for (Integer[] direction: directions) {\n            int x = i + direction[0], y = j + direction[1];\n            fish += dfs(x, y, grid);\n        }\n        return fish;\n    }\n\n    private boolean notValid(int i, int j, int[][] grid) {\n        return i < 0 || i >= grid.length || j < 0 || j >= grid[0].length;\n    }\n}\n```
['Depth-First Search', 'Java']