question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
maximum-number-of-fish-in-a-grid | 695. Max Area of Island | 695-max-area-of-island-by-votrubac-lngk | This is similar to 695. Max Area of Island.\n\nFor each "island" of water, it does not matter where fisherman starts. We just need to mark a visited cell by set | votrubac | NORMAL | 2023-04-29T16:01:01.057026+00:00 | 2023-04-29T16:10:20.218358+00:00 | 2,004 | false | This is similar to [695. Max Area of Island](https://leetcode.com/problems/max-area-of-island/).\n\nFor each "island" of water, it does not matter where fisherman starts. We just need to mark a visited cell by setting it to zero.\n\n```cpp \nint dfs(int r, int c, vector<vector<int>>& g) {\n if (min(r, c) < 0 || r... | 19 | 3 | [] | 1 |
maximum-number-of-fish-in-a-grid | ez DFS, BFS vs UnionFind||C++ beats 100% | ez-dfsc-beats-100-by-anwendeng-nd07 | Intuition1st approach uses DFS.
2nd approach uses BFS.
3rd approach uses UnionFind
This problem has the identical solution with 695. Max Area of Island
thanks | anwendeng | NORMAL | 2025-01-28T00:20:30.749362+00:00 | 2025-01-28T14:14:17.278432+00:00 | 1,622 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
1st approach uses DFS.
2nd approach uses BFS.
3rd approach uses UnionFind
This problem has the identical solution with [695. Max Area of Island
](https://leetcode.com/problems/max-area-of-island/solutions/3548861/easy-c-solution-using-dfs-... | 18 | 4 | ['Depth-First Search', 'Breadth-First Search', 'Union Find', 'C++'] | 4 |
maximum-number-of-fish-in-a-grid | It is fishing time🎣 Maximum Fish Catcher! 🐟 | it-is-fishing-time-maximum-fish-catcher-uuoaj | 🧠 IntuitionThe problem involves exploring all possible paths from any starting water cell (r, c) to maximize the number of fish caught. This can be visualized a | lasheenwael9 | NORMAL | 2025-01-28T06:32:40.000931+00:00 | 2025-01-28T06:32:40.000931+00:00 | 557 | false | # 🧠 Intuition
The problem involves exploring all possible paths from any starting water cell `(r, c)` to maximize the number of fish caught. This can be visualized as a **graph traversal problem**, where cells are nodes, and adjacency defines edges.
We will simulate the fisher's movement using **Breadth-First Sea... | 14 | 3 | ['Array', 'Breadth-First Search', 'Matrix', 'Python', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | 2 Approaches 😈😈|| Beats 💯% with proof 📜 || Easy DFS 🌲 || Recursion 🔄 | 2-approaches-beats-with-proof-easy-dfs-r-n7tt | Approach - 1Complexity
Time complexity: O(M∗N)
Space complexity: O(M∗N)
CodeApproach - 2Complexity
Time complexity: O(M∗N)
Space complexity: O(1)
Code
Please | Garv_Virmani | NORMAL | 2025-01-28T06:29:04.021886+00:00 | 2025-01-28T06:29:04.021886+00:00 | 1,633 | false | 
```
Plzzz... Upvote!!
```
# Approach - 1
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity: $$O(M*N)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space c... | 13 | 0 | ['Array', 'Math', 'Depth-First Search', 'Recursion', 'Matrix', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 0 |
maximum-number-of-fish-in-a-grid | Explained | C++ | Java | DFS | BFS | Beginner Friendly Code | | explained-c-java-dfs-bfs-beginner-friend-qhnz | DFS Approach\n\n\n1. Define a helper function dfs that takes the grid, the row index r, and the column index c as arguments. The function returns the total numb | Rishabhsinghal12 | NORMAL | 2023-04-29T16:01:28.853373+00:00 | 2023-04-29T16:16:01.545185+00:00 | 1,678 | false | **DFS Approach**\n\n```\n1. Define a helper function dfs that takes the grid, the row index r, and the column index c as arguments. The function returns the total number of fish caught starting from the cell (r, c).\n2. In the dfs function, check if the current cell is out of bounds or a land cell. If so, return 0 (bas... | 12 | 2 | ['Depth-First Search', 'Breadth-First Search', 'C', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | [C++] DFS | BFS | Union Find | Maximum of Water Components | c-dfs-bfs-union-find-maximum-of-water-co-9uat | Intuition\nWe can traverse only one complete component of water cells and catch all the fishes in it. Do a DFS/BFS traversal on every water component and count | shivamaggarwal513 | NORMAL | 2023-04-29T16:02:20.721468+00:00 | 2023-05-14T11:25:54.866452+00:00 | 839 | false | # Intuition\nWe can traverse only one complete component of water cells and catch all the fishes in it. Do a DFS/BFS traversal on every water component and count total number of fishes in that component. Take maximum of all possible water components.\n\n# Recursive DFS\n```\nclass Solution {\nprivate:\n int countFis... | 11 | 0 | ['Depth-First Search', 'Breadth-First Search', 'Union Find', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | Simple java solution | simple-java-solution-by-siddhant_1602-s3ru | Complexity\n- Time complexity: O(mn)\n\n- Space complexity: O(mn)\n\n# Code\n\nclass Solution {\n public int findMaxFish(int[][] grid) {\n int sum=0;\ | Siddhant_1602 | NORMAL | 2023-04-29T16:01:00.126974+00:00 | 2023-04-30T04:08:04.512473+00:00 | 856 | false | # Complexity\n- Time complexity: $$O(m*n)$$\n\n- Space complexity: $$O(m*n)$$\n\n# Code\n```\nclass Solution {\n public int findMaxFish(int[][] grid) {\n int sum=0;\n for(int i=0;i<grid.length;i++)\n {\n for(int j=0;j<grid[0].length;j++)\n {\n if(grid[i][j]!=... | 11 | 2 | ['Java'] | 1 |
maximum-number-of-fish-in-a-grid | (BFS +DFS) Simple Solution ✅ | C++| Java | Python | JavaScript | bfs-dfs-simple-solution-c-java-python-ja-9gjq | ⬆️Upvote if it helps ⬆️Connect with me on Linkedin [Bijoy Sing]BFS solutionDFS SolutionIntuition 🧠When exploring grid-based problems with connected components, | BijoySingh7 | NORMAL | 2025-01-28T05:04:46.820108+00:00 | 2025-01-28T05:04:46.820108+00:00 | 1,248 | false | # ⬆️Upvote if it helps ⬆️
---
## Connect with me on Linkedin [Bijoy Sing]
---
# BFS solution
---
```cpp []
class Solution {
public:
int bfs(int i, int j, vector<vector<int>>& grid) {
vector<vector<int>> dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
queue<pair<int, int>> q;
int n = grid.siz... | 10 | 2 | ['Array', 'Depth-First Search', 'Breadth-First Search', 'Matrix', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 0 |
maximum-number-of-fish-in-a-grid | Easy Peasy DFS | easy-peasy-dfs-by-sky09-vm5p | \nclass Solution {\n \n private int solve(int i, int j, int m, int n, int[][] grid, boolean[][] vis){\n // return if wrong position\n\t if(i < 0 | | Sky09 | NORMAL | 2023-04-29T16:06:40.797820+00:00 | 2023-04-29T16:29:04.543260+00:00 | 1,083 | false | ```\nclass Solution {\n \n private int solve(int i, int j, int m, int n, int[][] grid, boolean[][] vis){\n // return if wrong position\n\t if(i < 0 || j < 0 || i == m || j == n || vis[i][j] || grid[i][j] == 0){\n return 0;\n }\n\t\t\n\t\t// mark visited\n vis[i][j] = true;\n\t\t\n... | 10 | 1 | ['Java'] | 3 |
maximum-number-of-fish-in-a-grid | Python 3 || 8 lines, dfs || T/S: 72% / 48% | python-3-8-lines-dfs-ts-72-48-by-spauldi-rui3 | \nclass Solution:\n def findMaxFish(self, grid: List[List[int]]) -> int:\n\n def dfs(r: int,c: int) -> int:\n\n if (r,c) not in unseen:retu | Spaulding_ | NORMAL | 2023-04-29T23:38:54.041406+00:00 | 2024-06-19T01:16:25.373816+00:00 | 593 | false | ```\nclass Solution:\n def findMaxFish(self, grid: List[List[int]]) -> int:\n\n def dfs(r: int,c: int) -> int:\n\n if (r,c) not in unseen:return 0\n\n unseen.remove((r,c))\n return grid[r][c] + dfs(r+1,c)+dfs(r,c+1)+dfs(r-1,c)+dfs(r,c-1)\n \n\n m, n, ans = le... | 9 | 0 | ['Python3'] | 2 |
maximum-number-of-fish-in-a-grid | **Java** BFS Code || With Explanation | java-bfs-code-with-explanation-by-mjashw-vf1a | * Please upvote if it is helpful *\n\n# Explanation\n- Given that we have to choose optimal cell i.e grid[r][c] > 0 { water cell } in order to find the maximum | Mjashwanth | NORMAL | 2023-04-29T16:51:59.762801+00:00 | 2023-04-29T16:52:10.987743+00:00 | 1,027 | false | # ********** Please upvote if it is helpful **********\n\n# Explanation\n- Given that we have to choose optimal cell i.e grid[r][c] > 0 { water cell } in order to find the maximum fishes we can get.\n- Traverse the given grid and apply **BFS** on grid[r][c] > 0\n- We have to calculate the maximum fishes using bfs funct... | 7 | 1 | ['Stack', 'Java'] | 2 |
maximum-number-of-fish-in-a-grid | Easy to understand || Simple DFS | easy-to-understand-simple-dfs-by-mohakha-q54q | Given : We can start at any water cell \n#So why not do the same\n#For a given water cell, collect all the fishes from the cells which are \u2018connected\u2019 | mohakharjani | NORMAL | 2023-04-29T16:02:05.584026+00:00 | 2023-04-29T16:18:11.196654+00:00 | 862 | false | #Given : We can start at any water cell \n#So why not do the same\n#For a given water cell, collect all the fishes from the cells which are **\u2018connected\u2019 [directly/indirectly]** from that cell\n#So **get the count of fishes for each connected component, and then take the maximum**\n\n$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 6 | 0 | ['Java'] | 1 |
maximum-number-of-fish-in-a-grid | Simple Java solution (2 methods) | simple-java-solution-2-methods-by-siddha-ktyk | Method 1Visisted and non Visited array conceptComplexity
Time complexity: O(m∗n)
Space complexity: O(m∗n)
CodeMethod 2Adding values of a matrix conceptCompl | siddhant_2002 | NORMAL | 2025-01-28T04:20:23.215226+00:00 | 2025-01-28T04:20:23.215226+00:00 | 267 | false | # Method 1
# Visisted and non Visited array concept
# Complexity
- Time complexity: $$O(m*n)$$
- Space complexity: $$O(m*n)$$
# Code
```java []
class Solution {
public int findMaxFish(int[][] grid) {
int m = grid.length, n = grid[0].length;
int maxi = 0;
for(int i = 0; i < m; i++)
... | 6 | 0 | ['Array', 'Depth-First Search', 'Union Find', 'Matrix', 'Java'] | 0 |
maximum-number-of-fish-in-a-grid | ✅✅Beats 100%🔥C++🔥Python|| 🚀🚀Super Simple and Efficient Solution🚀🚀||🔥Python🔥C++✅✅ | beats-100cpython-super-simple-and-effici-gt1v | Complexity
Time complexity: O(mn)
Space complexity: O(mn)
⬆️👇⬆️UPVOTE it⬆️👇⬆️Code⬆️👇⬆️UPVOTE it⬆️👇⬆️ | shobhit_yadav | NORMAL | 2025-01-28T03:18:38.146816+00:00 | 2025-01-28T03:18:38.146816+00:00 | 492 | false | # Complexity
- Time complexity: $$O(mn)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: $$O(mn)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
⬆️👇⬆️UPVOTE it⬆️👇⬆️
# Code
```cpp []
class Solution {
public:
int findMaxFish(vector<vector<int>>& grid) {
int ans = 0;
for ... | 6 | 0 | ['Array', 'Depth-First Search', 'Breadth-First Search', 'Union Find', 'Matrix', 'C++', 'Python3'] | 0 |
maximum-number-of-fish-in-a-grid | 🔥BEATS 💯 % 🎯 |✨SUPER EASY BEGINNERS 👏| JAVA | C | C++ | PYTHON| JAVASCRIPT | DART | beats-super-easy-beginners-java-c-c-pyth-5m78 | IntuitionThe problem requires us to find the maximum number of fish that can be caught in a grid, where each cell can contain a certain number of fish. The goal | CodeWithSparsh | NORMAL | 2025-01-28T15:52:36.449521+00:00 | 2025-01-28T15:55:21.168436+00:00 | 189 | false | 
---

---
## Intuition
The problem requires us to find the maximum number of fish th... | 5 | 0 | ['Array', 'Depth-First Search', 'C', 'Matrix', 'C++', 'Java', 'Python3', 'JavaScript', 'Dart'] | 2 |
maximum-number-of-fish-in-a-grid | Maximum Number of Fish in a Grid [C++] | maximum-number-of-fish-in-a-grid-c-by-mo-yl4y | Intuition:The approach uses DFS to traverse connected non-zero cells, treating them as a single component (or "pond"). Each DFS call sums the fish count for all | moveeeax | NORMAL | 2025-01-28T02:54:22.855211+00:00 | 2025-01-28T02:54:22.855211+00:00 | 26 | false | ### Intuition:
The approach uses DFS to traverse connected non-zero cells, treating them as a single component (or "pond"). Each DFS call sums the fish count for all connected cells and updates the maximum count found.
### Approach:
1. **DFS Traversal**: Each cell with non-zero fish count acts as a starting point. The... | 5 | 0 | ['C++'] | 0 |
maximum-number-of-fish-in-a-grid | Maximum Number of Fish in a Grid - Solution Explanation and Code (Video Solution Available) | maximum-number-of-fish-in-a-grid-solutio-7mwj | Video SolutionIntuitionThe problem involves finding the maximum number of fishes that can be collected from connected cells in a grid. My initial thought was to | CodeCrack7 | NORMAL | 2025-01-28T02:21:21.184469+00:00 | 2025-01-28T02:21:21.184469+00:00 | 387 | false | # Video Solution
[https://youtu.be/yOZ5-C8XFm4?si=hBbCvNYVg-WNPCY-]()
# Intuition
The problem involves finding the maximum number of fishes that can be collected from connected cells in a grid. My initial thought was to treat this as a graph traversal problem, where each cell in the grid represents a node, and edges co... | 5 | 0 | ['Java'] | 0 |
maximum-number-of-fish-in-a-grid | BFS || C++ || ✅Easy Solution | bfs-c-easy-solution-by-vamosabhinav-ehhh | Approach\nSimple BFS approach.\nEnter in a cell when grid[r][c]!=0 and search in neighbours cell using bfs whenever leaving that particular cell add this to our | VamosAbhinav | NORMAL | 2023-04-29T17:04:41.718226+00:00 | 2023-04-29T17:04:41.718269+00:00 | 479 | false | # Approach\nSimple BFS approach.\nEnter in a cell when grid[r][c]!=0 and search in neighbours cell using bfs whenever leaving that particular cell add this to our fish variable and put it equal to 0 that is grid[r][c]=0.\n\n# Complexity\n- Time complexity:\n O(n*m)\n\n- Space complexity:\n O(min(n,m))\n\n# Code\n```\... | 5 | 0 | ['C++'] | 0 |
maximum-number-of-fish-in-a-grid | 🔥C++ ✅✅ Best Solution ( 🔥 DFS 🔥 ) Easy to Understand💯💯 ⬆⬆⬆ | c-best-solution-dfs-easy-to-understand-b-7q5l | Intuition\n Describe your first thoughts on how to solve this problem. \nDFS\n\n\n# Code\n\nclass Solution {\npublic:\n \n int solve(vector<vector<int>>& | Sandipan58 | NORMAL | 2023-04-29T16:04:34.816620+00:00 | 2023-04-29T16:04:34.816683+00:00 | 306 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nDFS\n\n\n# Code\n```\nclass Solution {\npublic:\n \n int solve(vector<vector<int>>& grid, vector<vector<bool>>& visited, int r, int c) {\n visited[r][c] = true;\n int cnt = grid[r][c], n = grid.size(), m = grid[0].siz... | 5 | 0 | ['Depth-First Search', 'Breadth-First Search', 'Graph', 'Recursion', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | My first DFS solution 🚀 || No reference Needed just follow the sol. explanation || 100 % TC || C++ | my-first-dfs-solution-no-reference-neede-thy6 | Intuition 💡The problem involves finding the maximum number of fish that can be collected in a connected component of a grid. Each cell with a non-zero value rep | brijesh03032001 | NORMAL | 2025-01-28T22:30:10.970656+00:00 | 2025-01-28T22:30:10.970656+00:00 | 26 | false |
### Intuition 💡
The problem involves finding the maximum number of fish that can be collected in a connected component of a grid. Each cell with a non-zero value represents a pond, and we can "collect fish" by exploring all adjacent cells in the same connected component. This is a classic **grid traversal problem** s... | 4 | 0 | ['Array', 'Depth-First Search', 'Graph', 'Matrix', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | 💢Faster✅💯 Lesser C++✅Python3🐍✅Java✅C✅Python🐍✅C#✅💥🔥💫Explained☠💥🔥 Beats 💯 | faster-lesser-cpython3javacpythoncexplai-ky97 | IntuitionThis is a reference vedio for the Solution. I tried to explain the solution in best way i can, please watch out the solution.
Approach
JavaScript Code | Edwards310 | NORMAL | 2025-01-28T12:19:52.845079+00:00 | 2025-01-28T12:19:52.845079+00:00 | 221 | false | 
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
***This is a reference vedio for the Solution. I tried to explain the solution in best way i can, please watch out ... | 4 | 1 | ['Depth-First Search', 'Breadth-First Search', 'C', 'Python', 'C++', 'Java', 'Go', 'Python3', 'JavaScript', 'C#'] | 1 |
maximum-number-of-fish-in-a-grid | DFS || Java || Easy Solution || Beat 100% || | dfs-java-easy-solution-beat-100-by-mmohm-fjwc | To do this, we can use Depth-First Search (DFS), to explores all connected parts of a region recursivelyApproach
Walk Through the Grid:
Look at each cell in t | mmohmedjasim2005 | NORMAL | 2025-01-28T10:24:52.862051+00:00 | 2025-01-28T10:29:20.089088+00:00 | 9 | false | **To do this, we can use Depth-First Search (DFS), to explores all connected parts of a region recursively**
---
# Approach
1. **Walk Through the Grid**:
- Look at each cell in the grid. If the cell contains fish (not zero)...Start a **DFS search** from that cell to find all the fish from neighbor cell
2. **Ex... | 4 | 0 | ['Java'] | 1 |
maximum-number-of-fish-in-a-grid | ✅ Maximum Number of Fish in a Grid | JS🔥 | beats 99%🚀 | 🚀highly optimised & easy to understand ✅ | maximum-number-of-fish-in-a-grid-js-beat-kt7l | Intuition
To solve the Maximum Number of Fish in a Grid problem, we can use Depth-First Search (DFS) to explore the grid.
Approach
Start from every water cell ( | Naveen_sachan | NORMAL | 2025-01-28T03:34:33.236032+00:00 | 2025-01-28T03:34:33.236032+00:00 | 200 | false | # Intuition
- To solve the Maximum Number of Fish in a Grid problem, we can use Depth-First Search (DFS) to explore the grid.
# Approach
- Start from every water cell (grid[i][j] > 0).
- Use DFS to traverse all reachable water cells and collect the fish.
- Keep track of the maximum number of fish collected starting fro... | 4 | 0 | ['JavaScript'] | 1 |
maximum-number-of-fish-in-a-grid | Python | Simple DFS | O(m*n), O(m*n) | Beats 95% | python-simple-dfs-beats-95-by-2pillows-8om0 | CodeComplexity
Time complexity: O(m∗n). Visit each cell once, m*n total cells.
Space complexity: O(m∗n). Based on maximum recursion depth of m*n total cells. | 2pillows | NORMAL | 2025-01-28T00:52:46.160087+00:00 | 2025-01-28T05:01:07.964396+00:00 | 140 | false | # Code
```python3 []
class Solution:
def findMaxFish(self, grid: List[List[int]]) -> int:
def collect_fish(i, j):
num_fish = grid[i][j] # collect fish from current cell
grid[i][j] = 0 # caught fish in current cell, no more remaining
for di, dj in [(0, 1), (0, -1), (1, 0)... | 4 | 0 | ['Array', 'Depth-First Search', 'Matrix', 'Python3'] | 1 |
maximum-number-of-fish-in-a-grid | Five Lines Only - According to the Hints | five-lines-only-according-to-the-hints-b-svd5 | IntuitionJust use the Hints from the Problem description:💡Hint 1
Run DFS from each non-zero cell.💡Hint 2
Each time you pick a cell to start from, add up the num | charnavoki | NORMAL | 2025-01-28T00:21:42.744769+00:00 | 2025-01-28T10:05:15.685925+00:00 | 382 | false | # Intuition
Just use the Hints from the Problem description:
💡Hint 1
Run DFS from each non-zero cell.
💡Hint 2
Each time you pick a cell to start from, add up the number of fish contained in the cells you visit.
```javascript []
const deltas = [[1, 0], [-1, 0], [0, 1], [0, -1]];
var findMaxFish = function(grid) {... | 4 | 0 | ['JavaScript'] | 1 |
maximum-number-of-fish-in-a-grid | Python DFS Solution - O(m + n) | python-dfs-solution-om-n-by-richyrich200-ftpf | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | RichyRich2004 | NORMAL | 2025-01-28T00:14:19.344220+00:00 | 2025-01-28T00:14:19.344220+00:00 | 712 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 4 | 0 | ['Python3'] | 0 |
maximum-number-of-fish-in-a-grid | Best O(M*N) Solution | best-omn-solution-by-kumar21ayush03-3xn0 | Approach\nBFS Traversal\n\n# Complexity\n- Time complexity:\nO(mn)\n\n- Space complexity:\nO(mn) \n\n# Code\n\nclass Solution {\npublic:\n int traversal(int | kumar21ayush03 | NORMAL | 2023-08-23T11:02:32.852782+00:00 | 2023-08-23T11:02:32.852814+00:00 | 38 | false | # Approach\nBFS Traversal\n\n# Complexity\n- Time complexity:\n$$O(m*n)$$\n\n- Space complexity:\n$$O(m*n)$$ \n\n# Code\n```\nclass Solution {\npublic:\n int traversal(int i, int j, vector<vector<int>>& grid, vector<vector<int>>& vis) {\n int m = grid.size(), n = grid[0].size();\n int fish = 0;\n ... | 4 | 0 | ['C++'] | 1 |
maximum-number-of-fish-in-a-grid | C++ || DFS | c-dfs-by-ganeshkumawat8740-jwuk | Approach\nAPPLE DFS\n\n# Complexity\n- Time complexity:\nO(m*n)\n\n- Space complexity:\nO(1)\n\n# Code\n\nclass Solution {\npublic:\n void solve(int i,int j, | ganeshkumawat8740 | NORMAL | 2023-05-06T07:37:33.231173+00:00 | 2023-05-06T07:37:33.231216+00:00 | 218 | false | # Approach\nAPPLE DFS\n\n# Complexity\n- Time complexity:\nO(m*n)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nclass Solution {\npublic:\n void solve(int i,int j,int &m,int &n,vector<vector<int>> &g,int &k){\n if(i<0||j<0||i>=m||j>=n||g[i][j]==0)return;\n k += g[i][j];\n g[i][j] = 0;\n s... | 4 | 0 | ['Depth-First Search', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | Easy Solution | JAVA | DFS | easy-solution-java-dfs-by-tracey432-hgq0 | Intuition\nTo find the maximum fish a fisherman can obtain. The zero represent the land and the numbers represent the number of available fish.\n\n# Approach\n | tracey432 | NORMAL | 2023-04-30T06:17:05.727787+00:00 | 2023-04-30T15:16:44.096234+00:00 | 91 | false | # Intuition\nTo find the maximum fish a fisherman can obtain. The zero represent the land and the numbers represent the number of available fish.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- Initialize the maximum variable as global\n- Create a boolean matrix called visited to keep track on... | 4 | 0 | ['Depth-First Search', 'Java'] | 0 |
maximum-number-of-fish-in-a-grid | c++ DFS | c-dfs-by-augus7-bewf | \n# Code\n\nclass Solution {\n void dfs(int row, int col, vector<vector<int>>& grid, vector<vector<int>>& vis, int &fish) {\n int n = grid.size(), m = | Augus7 | NORMAL | 2023-04-29T17:21:00.513373+00:00 | 2023-04-29T17:21:00.513418+00:00 | 1,185 | false | \n# Code\n```\nclass Solution {\n void dfs(int row, int col, vector<vector<int>>& grid, vector<vector<int>>& vis, int &fish) {\n int n = grid.size(), m = grid[0].size(); \n vis[row][col] = 1;\n fish += grid[row][col];\n int r_dir[4] = {-1, 0, 1, 0};\n int c_dir[4] = {0, 1, 0, -1};\... | 4 | 0 | ['Depth-First Search', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | PYTHON 3 | EASY SOLUTION | python-3-easy-solution-by-honejzy-y8fw | 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 | honejzy | NORMAL | 2023-04-29T16:51:34.138701+00:00 | 2023-04-29T16:52:21.547335+00:00 | 392 | false | 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 corres... | 4 | 0 | ['Depth-First Search', 'Python3'] | 0 |
maximum-number-of-fish-in-a-grid | simple java bfs | simple-java-bfs-by-flyroko123-bts6 | \nclass pair{\n int x;int y;\n pair(int x1,int y1){\n x=x1;\n y=y1;\n }\n}\nclass Solution {\n public int findMaxFish(int[][] grid) {\ | flyRoko123 | NORMAL | 2023-04-29T16:01:27.714809+00:00 | 2023-04-29T16:01:27.714860+00:00 | 367 | false | ```\nclass pair{\n int x;int y;\n pair(int x1,int y1){\n x=x1;\n y=y1;\n }\n}\nclass Solution {\n public int findMaxFish(int[][] grid) {\n int m=grid.length;\n int n=grid[0].length;\n int max=0;\n // System.out.print(bfs(0,1,grid,m,n)+" ");\n for(int i=0;i<m;i... | 4 | 0 | ['Breadth-First Search'] | 0 |
maximum-number-of-fish-in-a-grid | JAVA CODE | java-code-by-aysha3211-543e | ApproachUsing DFSComplexity
Time complexity: O(m*n)
Space complexity: O(1)
Code | Aysha3211 | NORMAL | 2025-01-28T14:41:25.024552+00:00 | 2025-01-28T14:41:25.024552+00:00 | 71 | false |
# Approach
<!-- Describe your approach to solving the problem. -->
Using DFS
# Complexity
- Time complexity: O(m*n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```java []
class Solution {
private int m, n;
pri... | 3 | 0 | ['Java'] | 0 |
maximum-number-of-fish-in-a-grid | Easy to Understand, Beginner C++ | DFS | easy-to-understand-beginner-c-dfs-by-nik-qznw | IntuitionApproachComplexity
Time complexity: O(m*n)
Space complexity:
Code | Nikhilk18 | NORMAL | 2025-01-28T10:26:05.170925+00:00 | 2025-01-28T10:26:05.170925+00:00 | 220 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity: O(m*n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
#... | 3 | 0 | ['C++'] | 0 |
maximum-number-of-fish-in-a-grid | ✅ Easy to Understand | Graph Theory | DFS | Connected Components | Detailed Video Explanation 🔥 | easy-to-understand-graph-theory-dfs-conn-upk2 | IntuitionThe problem can be visualized as finding the maximum sum of fish in connected regions of a grid, where each region is defined by non-zero cells that ar | sahilpcs | NORMAL | 2025-01-28T08:50:51.467787+00:00 | 2025-01-28T08:50:51.467787+00:00 | 94 | false | # Intuition
The problem can be visualized as finding the maximum sum of fish in connected regions of a grid, where each region is defined by non-zero cells that are adjacent (either vertically or horizontally). A depth-first search (DFS) is well-suited for exploring such connected regions, as it allows us to traverse a... | 3 | 0 | ['Array', 'Depth-First Search', 'Breadth-First Search', 'Matrix', 'Java'] | 1 |
maximum-number-of-fish-in-a-grid | C++ Solution || Simple BFS | c-solution-simple-bfs-by-rohit_raj01-tqux | IntuitionThe problem can be approached by treating the grid as a graph where:
Each cell is a node.
Edges exist between adjacent cells that are non-zero.
The tas | Rohit_Raj01 | NORMAL | 2025-01-28T07:48:37.409941+00:00 | 2025-01-28T07:48:37.409941+00:00 | 170 | false | # Intuition
The problem can be approached by treating the grid as a graph where:
- Each cell is a node.
- Edges exist between adjacent cells that are non-zero.
The task is to find all connected components (regions) of the grid and calculate the sum of fish in each component. The largest sum is the desired answer.
# A... | 3 | 0 | ['Array', 'Breadth-First Search', 'Matrix', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | 🐟 Maximum Fish Catch 🚀 | Easy DFS Solution | Python 🧠 | Dive Into the Grid 🌊 | maximum-fish-catch-easy-dfs-solution-pyt-ca9j | IntuitionThe problem can be thought of as finding the largest connected "pool" of fish in the grid, where we traverse all possible water cells (non-zero values) | Hardikjp7 | NORMAL | 2025-01-28T05:06:16.009449+00:00 | 2025-01-28T05:06:16.009449+00:00 | 53 | false | # Intuition
The problem can be thought of as finding the largest connected "pool" of fish in the grid, where we traverse all possible water cells (non-zero values) starting from each cell. Depth First Search (DFS) is a suitable approach to explore connected components in the grid.
# Approach
1. Use DFS to explor... | 3 | 0 | ['Depth-First Search', 'Python3'] | 0 |
maximum-number-of-fish-in-a-grid | 🚀 Simple Approach Using Backtracking 🚀 [Step by Step Explanation] | simple-approach-using-backtracking-step-29bq4 | 🚀 Approach
We first run a traversal through the grid to find water cells.
When we find a water cell we need to go to all possible directions
left , right , up a | LeadingTheAbyss | NORMAL | 2025-01-28T04:21:11.712200+00:00 | 2025-01-28T04:21:11.712200+00:00 | 14 | false | # 🚀 Approach
- We first run a traversal through the grid to find water cells.
- When we find a water cell we need to go to all possible directions
`left` , `right` , `up` and `down`.
- Until we keep finding water cells we keep adding them in our fishes count.
- Lastly we use `maximumFishes` to count the maximum numb... | 3 | 0 | ['Array', 'Backtracking', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | 100% BEATS IN JAVA USING DFS O(M*N) SOLUTION | 100-beats-in-java-using-dfs-omn-solution-mlro | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | shyam4KB | NORMAL | 2025-01-28T03:50:44.423745+00:00 | 2025-01-28T03:50:44.423745+00:00 | 99 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 3 | 0 | ['Java'] | 1 |
maximum-number-of-fish-in-a-grid | DFS | BFS | 0ms - 100% | 8.04MB - 100% | dfs-bfs-0ms-100-804mb-100-by-dipak__pati-xe7b | DFSBFS | dipak__patil | NORMAL | 2025-01-28T02:14:38.081008+00:00 | 2025-01-28T02:14:38.081008+00:00 | 120 | false | 

# DFS
```golang []
func findM... | 3 | 0 | ['Depth-First Search', 'Go'] | 1 |
maximum-number-of-fish-in-a-grid | Easy & Detailed Approch 💡 | Simple BFS ✅ | All Languages 🔥 | easy-detailed-approch-simple-bfs-all-lan-c5sb | IntuitionThe problem requires finding the maximum number of fish that can be collected from any connected group of cells in a grid. Each cell may contain some f | himanshu_dhage | NORMAL | 2025-01-28T02:12:19.731633+00:00 | 2025-01-28T02:12:19.731633+00:00 | 290 | false | # Intuition
The problem requires finding the maximum number of fish that can be collected from any connected group of cells in a grid. Each cell may contain some fish, and we can move to adjacent cells (up, down, left, right) to collect fish from connected components. The intuition is to explore each connected componen... | 3 | 0 | ['Depth-First Search', 'Breadth-First Search', 'Graph', 'Queue', 'Matrix', 'C++', 'Java', 'Python3'] | 0 |
maximum-number-of-fish-in-a-grid | DFS Solution for 'Maximum Number of Fish in a Grid' | Intuitive & Clean Code 💡 | dfs-solution-for-maximum-number-of-fish-eyq0s | IntuitionThe problem is like finding the biggest group of fish in a grid. Think of each cell in the grid as a pond. If two ponds (cells) are next to each other | atharva_kalbande | NORMAL | 2025-01-28T00:56:11.284733+00:00 | 2025-01-28T00:56:11.284733+00:00 | 9 | false | # Intuition
The problem is like finding the biggest group of fish in a grid. Think of each cell in the grid as a pond. If two ponds (cells) are next to each other and have fish, we can treat them as part of the same group. Our goal is to figure out the total number of fish in the biggest group. To do this, we can explo... | 3 | 0 | ['Depth-First Search', 'Python'] | 0 |
maximum-number-of-fish-in-a-grid | Easy Approach C++ | Depth First Search | Maximum Number of Fishes in a Grid | easy-approach-c-depth-first-search-maxim-twgi | Approach\nDepth first Search.\n- Converted each traversed path to land cell so that a separate visited array is not required.\n\n# Code\ncpp []\nclass Solution | pegasus1801 | NORMAL | 2023-06-23T10:30:41.146173+00:00 | 2023-06-23T10:30:41.146191+00:00 | 51 | false | # Approach\nDepth first Search.\n- Converted each traversed path to land cell so that a separate `visited` array is not required.\n\n# Code\n```cpp []\nclass Solution {\npublic:\n\n bool isValid(int i, int j, int n, int m){\n return i>=0 && i<n && j>=0 && j<m;\n }\n int dfs(vector<vector<int>>& grid, in... | 3 | 0 | ['Depth-First Search', 'Graph', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | C++ || DFS || Similar to Number of Islands | c-dfs-similar-to-number-of-islands-by-te-gilo | Intuition\nSimple DFS involves calculating the sum of different islands and taking the maximum one.\nSimilar to Number of Islands problem (https://leetcode.com/ | TESLA_6447 | NORMAL | 2023-04-30T18:25:19.140570+00:00 | 2023-04-30T18:25:19.140609+00:00 | 298 | false | # Intuition\nSimple DFS involves calculating the sum of different islands and taking the maximum one.\nSimilar to Number of Islands problem (https://leetcode.com/problems/number-of-islands/).\n# Approach\nDepth First Search\n\n## Don\'t forget to upvote and give a like \uD83D\uDE43\n\n# Code\n```\nclass Solution {\npub... | 3 | 0 | ['Depth-First Search', 'Counting', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | Fully explained Java solution | fully-explained-java-solution-by-codehun-a6jh | \n# Code\n\nclass Solution {\n public int findMaxFish(int[][] grid) {\n int max=0;\n\t\t// Loop over the Entire Grid\n for(int i=0;i< grid.leng | codeHunter01 | NORMAL | 2023-04-30T01:05:05.023546+00:00 | 2023-04-30T01:05:05.023592+00:00 | 445 | false | \n# Code\n```\nclass Solution {\n public int findMaxFish(int[][] grid) {\n int max=0;\n\t\t// Loop over the Entire Grid\n for(int i=0;i< grid.length; i++){\n for(int j=0; j<grid[0].length; j++){\n\t\t\t // only call the dfs call when we encounter a value>0, then find the number of connect... | 3 | 0 | ['Depth-First Search', 'Graph', 'Java'] | 0 |
maximum-number-of-fish-in-a-grid | Easy DFS Solution | O(n) | Rust | easy-dfs-solution-on-rust-by-prog_jacob-7xza | Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n# Co | Prog_Jacob | NORMAL | 2023-04-29T16:12:11.729574+00:00 | 2023-04-29T16:12:11.729621+00:00 | 52 | false | # Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nimpl Solution {\n pub fn find_max_fish(mut grid: Vec<Vec<i32>>) -> i32 {\n let mut ans = 0;\n\n for i ... | 3 | 0 | ['Rust'] | 0 |
maximum-number-of-fish-in-a-grid | Simple || Clean || Java Solution | simple-clean-java-solution-by-himanshubh-om2v | \njava []\npublic class Solution {\n int max = 0, cur = 0;\n public int findMaxFish(int[][] grid) {\n for(int i=0; i<grid.length; i++){\n | HimanshuBhoir | NORMAL | 2023-04-29T16:04:58.536861+00:00 | 2023-04-29T16:04:58.536903+00:00 | 227 | false | \n```java []\npublic class Solution {\n int max = 0, cur = 0;\n public int findMaxFish(int[][] grid) {\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) continue;\n pass(grid, i, j);\n cur = 0;\n ... | 3 | 0 | ['Java'] | 0 |
maximum-number-of-fish-in-a-grid | Easy to understand [ Clean Solution ] DFS -> (python + java) | easy-to-understand-clean-solution-dfs-py-ws4e | T.C : O(n^2)\n\nPython\n\nclass Solution:\n def findMaxFish(self, grid: List[List[int]]) -> int:\n m, n = len(grid), len(grid[0])\n fishes = 0\ | KmrVikas | NORMAL | 2023-04-29T16:01:52.651015+00:00 | 2023-04-29T16:05:01.428232+00:00 | 406 | false | **T.C : O(n^2)**\n\n**Python**\n```\nclass Solution:\n def findMaxFish(self, grid: List[List[int]]) -> int:\n m, n = len(grid), len(grid[0])\n fishes = 0\n\n def catchFish(r, c):\n nonlocal fish\n if 0 <= r < m and 0 <= c < n and grid[r][c] > 0:\n fish += gri... | 3 | 0 | ['Python', 'Java'] | 0 |
maximum-number-of-fish-in-a-grid | C++ Easy and Clean DFS Solution, Explained, 0 ms Beats 100% | c-easy-and-clean-dfs-solution-explained-mzf08 | Algorithm Explanation:This algorithm uses Depth-First Search (DFS) to explore connected regions of non-zero fish values in a grid and finds the largest "lake" o | yehudisk | NORMAL | 2025-02-16T22:24:16.886846+00:00 | 2025-02-16T22:24:16.886846+00:00 | 4 | false | # Algorithm Explanation:
This algorithm uses Depth-First Search (DFS) to explore connected regions of non-zero fish values in a grid and finds the largest "lake" of fish.
##### Initialization:
We iterate over the entire grid to find unvisited cells with fish (grid[i][j] > 0).
We use a `visited` matrix to track which ... | 2 | 0 | ['C++'] | 0 |
maximum-number-of-fish-in-a-grid | DFS intuitive solution | dfs-intuitive-solution-by-kashyap_lokesh-cudx | IntuitionThink of this problem in terms of connected Components. We can catch all the fish in One connected component of the matrix. If we run a dfs on a cell w | kashyap_lokesh | NORMAL | 2025-01-28T18:11:29.979925+00:00 | 2025-01-28T18:11:29.979925+00:00 | 29 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Think of this problem in terms of connected Components. We can catch all the fish in One connected component of the matrix. If we run a dfs on a cell which is not visited, it will give us the count of all the fishes in that component. We ca... | 2 | 0 | ['C++'] | 0 |
maximum-number-of-fish-in-a-grid | Max Number in RUBY! | max-number-in-ruby-by-quantummaniac609-x15j | IntuitionWhen I first saw this problem, I realized that since the fisher can move to any adjacent water cell and collect fish multiple times, we need to find co | quantummaniac609 | NORMAL | 2025-01-28T17:43:28.344802+00:00 | 2025-01-28T17:43:28.344802+00:00 | 10 | false | # Intuition
When I first saw this problem, I realized that since the fisher can move to any adjacent water cell and collect fish multiple times, we need to find connected components of water cells and sum up all fish in each component. The answer would be the maximum sum among all components.
# Approach
1. **Iterate T... | 2 | 0 | ['Ruby'] | 0 |
maximum-number-of-fish-in-a-grid | Simple py,JAVA code explained in detail!! BFS!! | simple-pyjava-code-explained-in-detail-b-1u1l | Probelm statement
Given m*n matrix named grid
If grid[i][j]>0 then we have a fish in it.
we have to maximise the collection of fish such that we can either
Tak | arjunprabhakar1910 | NORMAL | 2025-01-28T16:19:57.635838+00:00 | 2025-01-29T15:33:55.741512+00:00 | 48 | false | ## Probelm statement
- Given `m*n` matrix named `grid`
- If `grid[i][j]>0` then we have a *fish* in it.
- we have to maximise the collection of fish such that we can either
- Take the fish in `grid[i][j]`.
- Move to water cell which is `grid[i][j]=0`.
---
# Approach:BFS
<!-- Describe your approach to solving ... | 2 | 0 | ['Breadth-First Search', 'Matrix', 'Java', 'Python3'] | 0 |
maximum-number-of-fish-in-a-grid | Maximum fish using DFS | maximum-fish-using-dfs-by-poornasri-aiy5 | IntuitionThe problem can be thought of as finding the connected components in a 2D grid where the grid cells represent fish counts in a pond. The goal is to fin | Poornasri | NORMAL | 2025-01-28T12:34:17.212090+00:00 | 2025-01-28T12:34:17.212090+00:00 | 24 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem can be thought of as finding the connected components in a 2D grid where the grid cells represent fish counts in a pond. The goal is to find the maximum sum of fish in any connected component (group of cells). This is a classic ... | 2 | 0 | ['Array', 'Depth-First Search', 'Matrix', 'Java'] | 0 |
maximum-number-of-fish-in-a-grid | Simple C++ Approach ✅ | Beats 100%🔥 | simple-c-approach-beats-100-by-ztvorcaln-5xk5 | Intuition 🧐The problem can be visualized as finding the maximum sum of connected components in a 2D grid where each cell represents the number of fish. A BFS or | its-pratik21 | NORMAL | 2025-01-28T09:55:28.468521+00:00 | 2025-01-28T09:55:28.468521+00:00 | 48 | false | # Intuition 🧐
The problem can be visualized as finding the maximum sum of connected components in a 2D grid where each cell represents the number of fish. A BFS or DFS traversal allows us to explore all connected cells efficiently, while keeping track of the sum for each connected region.
# Approach 🚀
1) Initializat... | 2 | 0 | ['Breadth-First Search', 'Graph', 'Matrix', 'C++'] | 1 |
maximum-number-of-fish-in-a-grid | ❄️Simple Recursion to solve easily- C++ || beats 100% 🔥 | simple-recursion-to-solve-easily-c-beats-x0a7 | IntuitionUsing Recursion to traverse each cell where there is fish and counting them. After Finishing I realised it's actually called DFS for searching like thi | Neerajdec2005 | NORMAL | 2025-01-28T07:11:41.156509+00:00 | 2025-01-28T07:11:41.156509+00:00 | 63 | false | # Intuition
Using Recursion to traverse each cell where there is fish and counting them. After Finishing I realised it's actually called DFS for searching like this. So this is a simple recursive DFS code.
# Approach
Traverse Each element from top right to botton left
```
for(int i=0;i<m;i++){
for(int j=0;j<n;j++)... | 2 | 0 | ['Array', 'Depth-First Search', 'Matrix', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | Simple solution Python3 | simple-solution-python3-by-flyer_51-e4kh | IntuitionThe problem requires finding the maximum number of fish in any connected component of a 2D grid. A connected component is defined by adjacent (up, down | flyer_51 | NORMAL | 2025-01-28T07:04:19.054104+00:00 | 2025-01-28T07:04:19.054104+00:00 | 7 | false | # Intuition
The problem requires finding the maximum number of fish in any connected component of a 2D grid. A connected component is defined by adjacent (up, down, left, right) cells with positive values. The goal is to traverse the grid and calculate the total fish count for each connected component, keeping track of... | 2 | 0 | ['Python3'] | 1 |
maximum-number-of-fish-in-a-grid | 🌟BFS for Beginners 💡 | 🎉 Effortless grid exploration with BFS 🧩. | bfs-for-beginners-effortless-grid-explor-mdry | Intuition 🧠
Find the largest group of connected cells with fish using BFS to calculate the total fish in each group. Track the maximum fish among all groups.
Ap | shubhamrajpoot_ | NORMAL | 2025-01-28T06:53:31.555049+00:00 | 2025-01-28T06:53:31.555049+00:00 | 216 | false | # Intuition 🧠
- Find the largest group of connected cells with fish using `BFS` to calculate the `total` fish in each group. Track the maximum fish among all groups.
# Approach 🚀
1. **Traverse Grid:** For each unvisited cell with fish, `start a BFS`.
2. **BFS Exploration:** Use a queue to explore all connected fish ... | 2 | 0 | ['Depth-First Search', 'Breadth-First Search', 'Matrix', 'Python', 'C++', 'Java', 'TypeScript', 'Rust', 'Ruby', 'JavaScript'] | 1 |
maximum-number-of-fish-in-a-grid | Maximum Number of Fish in a Grid (DFS ) | maximum-number-of-fish-in-a-grid-dfs-by-yu2wj | Code | wjq9YLqfKX | NORMAL | 2025-01-28T06:01:25.559803+00:00 | 2025-01-28T06:01:25.559803+00:00 | 23 | false | # Code
```javascript []
/**
* @param {number[][]} grid
* @return {number}
*/
var findMaxFish = function(grid) {
if (!grid || grid.length === 0) return 0;
let rows = grid.length
let cols = grid[0].length
let max = 0;
function dfs(i, j){
if (i < 0 || i >= rows || j < 0 || j >= cols || grid[i... | 2 | 0 | ['Depth-First Search', 'JavaScript'] | 0 |
maximum-number-of-fish-in-a-grid | CPP || !00% beats || easy to understand || BFS | cpp-00-beats-easy-to-understand-bfs-by-a-rx64 | New achievement unlocked-------->
Complexity
Time complexity: O(N*M)
Space complexity: O(N*M)
Code | apoorvjain7222 | NORMAL | 2025-01-28T05:55:13.685723+00:00 | 2025-01-28T05:55:13.685723+00:00 | 52 | false | New achievement unlocked-------->

# Complexity
- Time complexity: O(N*M)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: O(N*M)
<!-- Add your space complexity here, e.g.... | 2 | 0 | ['Array', 'Breadth-First Search', 'Union Find', 'Matrix', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | Easy to understand C++ Solution | easy-to-understand-c-solution-by-khushia-6m86 | IntuitionThis problem is similar to: https://leetcode.com/problems/number-of-islands/description/Start a DFS from every water node to find how many fishes can b | khushiagrwl | NORMAL | 2025-01-28T05:51:37.364912+00:00 | 2025-01-28T05:51:52.600581+00:00 | 86 | false | # Intuition
This problem is similar to: https://leetcode.com/problems/number-of-islands/description/
Start a DFS from every water node to find how many fishes can be caught starting from current node.
Once fishes from current index(i, j) are caught - it can be marked visited to avoid recomputation.
Note that one wat... | 2 | 0 | ['Depth-First Search', 'Matrix', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | DFS Concept✅|| ⚡Runtime 5 ms || Java Approach 👍 | dfs-concept-runtime-5-ms-java-approach-b-0v6j | IntuitionThe problem involves finding the maximum number of fish in connected regions of a grid. Each cell in the grid represents water, and the value in the ce | i_dm | NORMAL | 2025-01-28T05:44:03.263309+00:00 | 2025-01-28T05:44:03.263309+00:00 | 21 | false | 
# Intuition
The problem involves finding the maximum number of fish in connected regions of a grid. Each cell in the grid represents water, and the value in the cell represents the number of fish. Conne... | 2 | 0 | ['Array', 'Math', 'Depth-First Search', 'Java'] | 0 |
maximum-number-of-fish-in-a-grid | EASY SOLUTION | JAVA | (Clean Code) | Explained with Comments !! | easy-solution-java-clean-code-explained-zaxhk | Code | Siddharth_Bahuguna | NORMAL | 2025-01-28T05:04:55.593103+00:00 | 2025-01-28T05:04:55.593103+00:00 | 67 | false |
# Code
```java []
class Solution {
int rows;
int cols;
public int findMaxFish(int[][] grid) {
// Store the number of rows and columns in the grid
rows=grid.length;
cols=grid[0].length;
int maxFishes=0;
for(int i=0;i<rows;i++){
for(int j=0;j<cols;j++){
... | 2 | 0 | ['Java'] | 0 |
maximum-number-of-fish-in-a-grid | Finding Maximum Fish with DFS 🐟💡 | finding-maximum-fish-with-dfs-by-rshohru-j6ms | To solve this problem, we can use Depth-First Search (DFS) to explore connected regions of the grid. Here's the step-by-step approach:
Iterate Through the Grid | rshohruh | NORMAL | 2025-01-28T04:37:27.043374+00:00 | 2025-01-28T04:37:27.043374+00:00 | 166 | false | To solve this problem, we can use **Depth-First Search (DFS)** to explore connected regions of the grid. Here's the step-by-step approach:
1. **Iterate Through the Grid**: Loop through all cells in the grid. If a cell contains fish (`grid[i][j] > 0`), it is the starting point for a new connected region.
2. **Use DFS ... | 2 | 0 | ['Array', 'Depth-First Search', 'Matrix', 'C++', 'Java', 'Go', 'Python3', 'C#'] | 0 |
maximum-number-of-fish-in-a-grid | DSU Solution || Path Compression and Ackermann Concept Explained || Time And Space Explained || | dsu-solution-path-compression-and-ackerm-6giw | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Heisenberg_wc | NORMAL | 2025-01-28T04:21:07.374559+00:00 | 2025-01-28T04:21:07.374559+00:00 | 49 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 2 | 0 | ['C++'] | 0 |
maximum-number-of-fish-in-a-grid | DFS solution || C++ || Python | dfs-solution-c-python-by-anurag_basuri-ibpn | IntuitionThe problem involves identifying connected components in a grid where each cell represents either a body of water (0) or a cluster of fish (non-zero po | Anurag_Basuri | NORMAL | 2025-01-28T04:11:17.130053+00:00 | 2025-01-28T04:11:17.130053+00:00 | 85 | false | # Intuition
The problem involves identifying connected components in a grid where each cell represents either a body of water (0) or a cluster of fish (non-zero positive integers). The goal is to calculate the maximum number of fish in any connected cluster, where connectivity is defined as adjacency in the 4 cardinal ... | 2 | 0 | ['Array', 'Depth-First Search', 'Matrix', 'C++', 'Python3'] | 0 |
maximum-number-of-fish-in-a-grid | leetcodedaybyday - Beats 84.06% with C++ and Beats 73.41% with Python3 | leetcodedaybyday-beats-8406-with-c-and-b-ryk7 | IntuitionTo solve the problem, we can leverage a Depth-First Search (DFS) approach. The idea is to explore all connected cells in the grid that contain non-zero | tuanlong1106 | NORMAL | 2025-01-28T03:58:45.710574+00:00 | 2025-01-28T03:58:45.710574+00:00 | 102 | false | # Intuition
To solve the problem, we can leverage a Depth-First Search (DFS) approach. The idea is to explore all connected cells in the grid that contain non-zero values, as they represent the regions containing fish. By performing DFS for each cell in the grid, we can calculate the total number of fish in connected c... | 2 | 0 | ['Depth-First Search', 'Matrix', 'C++', 'Python3'] | 1 |
maximum-number-of-fish-in-a-grid | ✅ ⟣ Java Solution ⟢ | java-solution-by-harsh__005-8tzi | Code | Harsh__005 | NORMAL | 2025-01-28T02:40:49.089420+00:00 | 2025-01-28T02:40:49.089420+00:00 | 52 | false | # Code
```java []
class Solution {
int dirs[][] = {{-1,0}, {1,0}, {0,-1}, {0,1}};
private int solve(boolean[][] vis, int i, int j, int r, int c, int[][] grid) {
vis[i][j] = true;
int sum = grid[i][j];
for(int dir[]: dirs) {
int nr = i + dir[0], nc = j + dir[1];
if... | 2 | 0 | ['Java'] | 1 |
maximum-number-of-fish-in-a-grid | Maximum Number Of Fish In the grid - Easy Solution - Nice Explanation ‼️💯 | maximum-number-of-fish-in-the-grid-easy-ibu7w | Intuition
We can use bfs to keep track of the adjacent cells and once the cell is visited,it's marked as 0 in-place.
At each bfs,we'll obtain max number of f | RAJESWARI_P | NORMAL | 2025-01-28T02:40:36.959367+00:00 | 2025-01-28T02:40:36.959367+00:00 | 32 | false | # Intuition
1. We can use bfs to keep track of the adjacent cells and once the cell is visited,it's marked as 0 in-place.
1. At each bfs,we'll obtain max number of fishes, so that we'll get the maximum of the fishes that can be obtained in the grid.
<!-- Describe your first thoughts on how to solve this problem. -->
... | 2 | 0 | ['Array', 'Breadth-First Search', 'Matrix', 'Java'] | 0 |
maximum-number-of-fish-in-a-grid | BFS & DFS Approach Python Solution | bfs-dfs-approach-python-solution-by-feni-orii | DFS Solution# IntuitionThe problem involves finding the maximum number of fish that can be collected in a grid by moving in 4 possible directions (up, down, lef | fenilpatel61 | NORMAL | 2025-01-28T02:33:38.632970+00:00 | 2025-01-28T02:36:07.357092+00:00 | 19 | false | ### DFS Solution
---
#### **# Intuition**
The problem involves finding the maximum number of fish that can be collected in a grid by moving in 4 possible directions (up, down, left, right). Since connected components of non-zero cells represent a valid path to collect fish, the goal is to explore all such components ... | 2 | 0 | ['Python3'] | 0 |
maximum-number-of-fish-in-a-grid | Easy C++ solution | easy-c-solution-by-harsh_indoria-g81q | IntuitionThe problem involves finding the maximum sum of connected non-zero cells in a grid. This suggests a graph traversal problem, where each non-zero cell i | HARSH_INDORIA | NORMAL | 2025-01-28T02:18:26.334091+00:00 | 2025-01-28T02:18:26.334091+00:00 | 105 | false | # Intuition
The problem involves finding the maximum sum of connected non-zero cells in a grid. This suggests a **graph traversal problem**, where each non-zero cell is a node, and edges exist between adjacent non-zero cells (up, down, left, right). We can treat the problem as finding the largest **connected component*... | 2 | 0 | ['Depth-First Search', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | DFS from Water Cells | C++, Python, Java | dfs-from-water-cells-c-python-java-by-no-2z8e | ApproachPerform a DFS starting from every unmarked water cell where you visit every 4-directionally adjacent cells (up, down, left, right). When you visit an ad | not_yl3 | NORMAL | 2025-01-28T00:50:14.611269+00:00 | 2025-01-28T00:50:14.611269+00:00 | 245 | false | # Approach
<!-- Describe your approach to solving the problem. -->
Perform a DFS starting from every unmarked water cell where you visit every 4-directionally adjacent cells (up, down, left, right). When you visit an adjacent water cell, mark it as visited by setting it to zero so that we don't visit it again. After ea... | 2 | 0 | ['Array', 'Depth-First Search', 'Breadth-First Search', 'Union Find', 'C', 'Matrix', 'Python', 'C++', 'Java', 'Python3'] | 0 |
maximum-number-of-fish-in-a-grid | Swift💯DFS | swiftdfs-by-upvotethispls-2uo8 | DFS Flood Fill (accepted answer) | UpvoteThisPls | NORMAL | 2025-01-28T00:26:23.025864+00:00 | 2025-01-28T00:26:23.025864+00:00 | 69 | false | **DFS Flood Fill (accepted answer)**
```
class Solution {
func findMaxFish(_ grid: consuming [[Int]]) -> Int {
let (rows,cols) = (grid.indices, grid[0].indices)
func dfs(_ x:Int, _ y:Int) -> Int {
guard rows ~= y, cols ~= x, grid[y][x] > 0 else { return 0 }
var fish = grid[y][x]
grid[y][x] =... | 2 | 0 | ['Depth-First Search', 'Recursion', 'Swift'] | 0 |
maximum-number-of-fish-in-a-grid | C++ | DFS | c-dfs-by-ahmedsayed1-nr1s | Code | AhmedSayed1 | NORMAL | 2025-01-28T00:19:59.841607+00:00 | 2025-01-28T00:19:59.841607+00:00 | 145 | false | # Code
```cpp []
class Solution {
public:
int dx[4]{1, -1 , 0 ,0}, dy[4]{0, 0 , 1 , -1};
int dfs(int i, int j, vector<vector<int>>& grid){
int ret = grid[i][j];
grid[i][j] = 0;
for(int k = 0 ;k < 4 ;k++){
int a = i + dx[k], b = j + dy[k];
if(min(a, b) >= 0 && a <... | 2 | 0 | ['Depth-First Search', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | "🚀🚀Maximize Fish Catch🔥🔥|| ✅Efficient Solution by Kanishka✅|| 🔥🔥Beginner Friendly Solution🚀🚀 | maximize-fish-catch-efficient-solution-b-loef | 🧠 IntuitionThe first thought is to traverse the grid and explore each possible connected component of non-zero fish values using Depth-First Search (DFS). The g | kanishka21535 | NORMAL | 2025-01-28T00:12:13.765672+00:00 | 2025-01-28T00:12:13.765672+00:00 | 30 | false | # 🧠 Intuition
The first thought is to traverse the grid and explore each possible connected component of non-zero fish values using Depth-First Search (DFS). The goal is to find the maximum fish count in any connected component.
# 🔍 Approach
Here's the approach step-by-step:
1. **Initialize Variables**: Set up a `vi... | 2 | 0 | ['Depth-First Search', 'Java'] | 0 |
maximum-number-of-fish-in-a-grid | "🚀🚀Maximize Fish Catch🔥🔥|| ✅Efficient Solution by Dhandapani✅|| 🔥🔥Beats 100% in Java🚀🚀 | maximize-fish-catch-efficient-solution-b-qqal | 🧠 IntuitionThe first thought is to traverse the grid and explore each possible connected component of non-zero fish values using Depth-First Search (DFS). The g | Dhandapanimaruthasalam | NORMAL | 2025-01-28T00:06:43.309262+00:00 | 2025-01-28T00:06:43.309262+00:00 | 134 | false | # 🧠 Intuition
The first thought is to traverse the grid and explore each possible connected component of non-zero fish values using Depth-First Search (DFS). The goal is to find the maximum fish count in any connected component.
# 🔍 Approach
Here's the approach step-by-step:
1. **Initialize Variables**: Set up a `vi... | 2 | 0 | ['Depth-First Search', 'Java'] | 0 |
maximum-number-of-fish-in-a-grid | Rust 0ms 🔥 2.15Mb ☄️ One Function Solution 🦀 | rust-0ms-215mb-one-function-solution-by-x14xn | Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n# Co | rony0000013 | NORMAL | 2024-06-01T13:30:42.946992+00:00 | 2024-06-01T13:30:42.947025+00:00 | 22 | false | # Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nimpl Solution {\n pub fn find_max_fish(mut grid: Vec<Vec<i32>>) -> i32 {\n fn dfs(v: &mut Vec<Vec<i32>>, i: u... | 2 | 0 | ['Rust'] | 1 |
maximum-number-of-fish-in-a-grid | Easy DFS || Beats 70% || Java | easy-dfs-beats-70-java-by-youssef1998-nlw0 | 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 | youssef1998 | NORMAL | 2023-07-31T14:20:28.396890+00:00 | 2023-07-31T14:20:28.396916+00:00 | 17 | false | # 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[]... | 2 | 0 | ['Depth-First Search', 'Java'] | 0 |
maximum-number-of-fish-in-a-grid | ✅✅DFS Approach || Easy to understand || Standard method || C++ || beats 100% | dfs-approach-easy-to-understand-standard-z68e | Intuition\n Describe your first thoughts on how to solve this problem. \nThis is a standard traversal problem where we will traverse each component, find the su | 2uringTested | NORMAL | 2023-05-11T09:22:58.377087+00:00 | 2023-05-11T09:22:58.377119+00:00 | 30 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis is a standard traversal problem where we will traverse each component, find the sum of fishes on each component and find out the maximum of all the sums.\n\n# Complexity\n- Time complexity: O(M*N)\n<!-- Add your time complexity here,... | 2 | 0 | ['Depth-First Search', 'Graph', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | ✅ C++ BFS Solution ✅ | c-bfs-solution-by-akshay_ar_2002-pxq5 | Intuition\n Describe your first thoughts on how to solve this problem. \n- BFS traversal on the Connected Components. Just a variation of LC #200[Number Of Isla | akshay_AR_2002 | NORMAL | 2023-05-07T17:22:33.411067+00:00 | 2023-05-07T17:23:12.948030+00:00 | 47 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- BFS traversal on the Connected Components. Just a variation of LC #200[Number Of Islands]\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n- The code uses a breadth-first search (BFS) approach to traverse the wate... | 2 | 0 | ['C++'] | 0 |
maximum-number-of-fish-in-a-grid | C++|| Simple BFS Approach | c-simple-bfs-approach-by-arko-816-al13 | \nclass Solution {\npublic:\n int maxi=INT_MIN;\n int dx[4]={0,1,0,-1};\n int dy[4]={1,0,-1,0};\n void f(int i,int j,int m,int n,vector<vector<int>> | Arko-816 | NORMAL | 2023-04-29T16:54:18.931353+00:00 | 2023-04-29T16:54:18.931392+00:00 | 233 | false | ```\nclass Solution {\npublic:\n int maxi=INT_MIN;\n int dx[4]={0,1,0,-1};\n int dy[4]={1,0,-1,0};\n void f(int i,int j,int m,int n,vector<vector<int>> &grid,vector<vector<int>> &vis)\n {\n queue<pair<int,int>> q;\n q.push({i,j});\n vis[i][j]=1;\n int s=0;\n while(!q.em... | 2 | 0 | [] | 0 |
maximum-number-of-fish-in-a-grid | C++ Solution | c-solution-by-pranto1209-33ud | Approach\n Describe your approach to solving the problem. \n DFS 2D\n\n# Code\n\nclass Solution {\npublic:\n vector<vector<int>> grids;\n int n, m, cnt | pranto1209 | NORMAL | 2023-04-29T16:52:26.026606+00:00 | 2023-04-29T16:52:26.026648+00:00 | 340 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\n DFS 2D\n\n# Code\n```\nclass Solution {\npublic:\n vector<vector<int>> grids;\n int n, m, cnt, vis[11][11];\n \n bool valid(int x, int y) {\n if(x >= 0 and x < n and y >= 0 and y < m and !vis[x][y] and grids[x][y]) return true;\... | 2 | 0 | ['C++'] | 0 |
maximum-number-of-fish-in-a-grid | ✔💯 DFS || MOST SIMPLE SOLUTION|| C++ | dfs-most-simple-solution-c-by-yash___sha-t3fb | \n\nclass Solution {\npublic:\n void solve(int i,int j,int &a,int &b,int &sum,int &ans,vector<vector<int>> &g){\n ans = max(ans,sum);\n if(i<0| | yash___sharma_ | NORMAL | 2023-04-29T16:11:14.497722+00:00 | 2023-04-29T16:11:14.497782+00:00 | 365 | false | \n````\nclass Solution {\npublic:\n void solve(int i,int j,int &a,int &b,int &sum,int &ans,vector<vector<int>> &g){\n ans = max(ans,sum);\n if(i<0||j<0||i>=a||j>=b||g[i][j]==0){\n return;\n }\n sum += g[i][j];\n g[i][j] = 0;\n solve(i+1,j,a,b,sum,ans,g);\n ... | 2 | 0 | ['Depth-First Search', 'Graph', 'C', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | Intuitive JavaScript solution using DFS | intuitive-javascript-solution-using-dfs-xqr8q | Approach\n Describe your approach to solving the problem. \nDFS\n\n# Complexity\n- Time complexity: O(M * N)\n Add your time complexity here, e.g. O(n) \n\n- Sp | deleted_user | NORMAL | 2023-04-29T16:08:24.975609+00:00 | 2023-04-29T16:09:08.747372+00:00 | 193 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\nDFS\n\n# Complexity\n- Time complexity: O(M * N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(M * N)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * @param {number[][]} grid\n * @retur... | 2 | 0 | ['Depth-First Search', 'JavaScript'] | 1 |
maximum-number-of-fish-in-a-grid | SIMPLE BFS solution | | Connected Components | | C++ | simple-bfs-solution-connected-components-fhmx | \n# Approach\nSame as island problem connected component. Using BFS traverse all the components and return the maximum sum of the the components.\n Describe you | yashpal_97 | NORMAL | 2023-04-29T16:04:30.105457+00:00 | 2023-04-29T16:04:30.105526+00:00 | 202 | false | \n# Approach\nSame as island problem connected component. Using BFS traverse all the components and return the maximum sum of the the components.\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: o(n*m)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexi... | 2 | 0 | ['C++'] | 0 |
maximum-number-of-fish-in-a-grid | Concise DFS | C++ | concise-dfs-c-by-tusharbhart-bz3q | \nclass Solution {\n vector<int> dx = {-1, 0, 1, 0}, dy = {0, 1, 0, -1};\n int dfs(int i, int j, vector<vector<int>>& grid, vector<vector<int>>& vis, int | TusharBhart | NORMAL | 2023-04-29T16:01:55.740463+00:00 | 2023-04-29T16:01:55.740515+00:00 | 191 | false | ```\nclass Solution {\n vector<int> dx = {-1, 0, 1, 0}, dy = {0, 1, 0, -1};\n int dfs(int i, int j, vector<vector<int>>& grid, vector<vector<int>>& vis, int n, int m) {\n vis[i][j] = 1;\n int cnt = grid[i][j];\n \n for(int k=0; k<4; k++) {\n int x = i + dx[k], y = j + dy[k];... | 2 | 0 | ['Depth-First Search', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | Starting is hard ,Flow is tough and end is beauty given by God. | starting-is-hard-flow-is-tough-and-end-i-ey5p | IntuitionNothing but just Dfs.Approachcheck the water count the fish and then give it back the problem is similar to the number of island.Complexity
Time compl | Madhavendrasinh44 | NORMAL | 2025-03-30T15:30:03.020114+00:00 | 2025-03-30T15:30:03.020114+00:00 | 6 | false | # Intuition
Nothing but just Dfs.
# Approach
check the water count the fish and then give it back the problem is similar to the number of island.
# Complexity
- Time complexity: $$O(n*m)$$
- Space complexity: $$O(n*m)$$
# Code
```java []
class Solution {
public int findMaxFish(int[][] grid1) {
int ans=0;... | 1 | 0 | ['Depth-First Search', 'Matrix', 'Java'] | 0 |
maximum-number-of-fish-in-a-grid | C# | c-by-adchoudhary-f094 | Code | adchoudhary | NORMAL | 2025-02-27T04:31:41.955822+00:00 | 2025-02-27T04:31:41.955822+00:00 | 4 | false | # Code
```csharp []
public class Solution {
public int FindMaxFish(int[][] grid) {
int m = grid.Length;
int n = grid[0].Length;
int maxFish = 0;
// Directions for moving up, down, left, right
int[][] directions = new int[][] {
new int[] { 1, 0 }, // down
new int[] { -1, 0 }, // ... | 1 | 0 | ['C#'] | 0 |
maximum-number-of-fish-in-a-grid | Can't get easier than that | cant-get-easier-than-that-by-lucifer_fa1-s0uy | IntuitionApproachComplexity
Time complexity:
Space complexity:
BFSDFS | Lucifer_Fa11in | NORMAL | 2025-02-02T07:54:07.429807+00:00 | 2025-02-02T07:54:07.429807+00:00 | 4 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# BFS
``... | 1 | 0 | ['Depth-First Search', 'Breadth-First Search', 'Queue', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | simple py sol - dfs | simple-py-sol-dfs-by-noam971-le5l | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | noam971 | NORMAL | 2025-01-28T22:51:42.870901+00:00 | 2025-01-28T22:53:23.432184+00:00 | 6 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 1 | 0 | ['Python3'] | 0 |
maximum-number-of-fish-in-a-grid | easy c++ sol | easy-c-sol-by-shivesh977-rrpe | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | Shivesh977 | NORMAL | 2025-01-28T22:27:13.420473+00:00 | 2025-01-28T22:27:13.420473+00:00 | 7 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 1 | 0 | ['C++'] | 0 |
maximum-number-of-fish-in-a-grid | Python, classic solution with stack | python-classic-solution-with-stack-by-de-h326 | IntuitionFew steps:
determind cells with water
for next available cell in water do explore with counting fish
compute max per "pond"
ApproachComplexity
Time co | dev_lvl_80 | NORMAL | 2025-01-28T21:50:06.812452+00:00 | 2025-01-28T21:50:06.812452+00:00 | 5 | false | # Intuition
Few steps:
- determind cells with water
- for next available cell in water do explore with counting fish
- compute max per "pond"
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
O(N)
- Space complexity:
O(N)
# Code
```python3 []
class Solution:
def... | 1 | 0 | ['Python3'] | 0 |
maximum-number-of-fish-in-a-grid | Exploring Connected Waters | c++ | Easy | DFS 🚀🚀 | exploring-connected-waters-c-easy-dfs-by-yp4n | IntuitionThe problem can be viewed as finding the maximum sum of connected components in a grid, where each cell represents a node, and its value represents the | kirigaya07 | NORMAL | 2025-01-28T20:18:58.180991+00:00 | 2025-01-28T20:18:58.180991+00:00 | 5 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem can be viewed as finding the maximum sum of connected components in a grid, where each cell represents a node, and its value represents the number of fish present. The goal is to explore all connected cells with non-zero values ... | 1 | 0 | ['Depth-First Search', 'Graph', 'Ordered Set', 'C++'] | 0 |
maximum-number-of-fish-in-a-grid | DFS solytion | dfs-solytion-by-ishaan_p-2r2q | Code | Ishaan_P | NORMAL | 2025-01-28T20:11:30.883693+00:00 | 2025-01-28T20:11:30.883693+00:00 | 7 | false |
# Code
```java []
class Solution {
public int findMaxFish(int[][] grid) {
int maxFishyFishies = 0;
boolean[][] visited = new boolean[grid.length][grid[0].length]; //dont modify input
for(int i = 0; i < grid.length; i++){
for(int j = 0; j < grid[0].length; j++){
... | 1 | 0 | ['Java'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | [Python] BFS * BFS | 130ms | beats 95% | Explained & Commented | python-bfs-bfs-130ms-beats-95-explained-lyius | Lets break the question into simple parts:\n\n1. Lets think that we have no person and we have to find the minimum path between box and the target. Easy right? | zypher27 | NORMAL | 2020-06-18T15:36:35.676154+00:00 | 2021-10-05T05:51:03.254347+00:00 | 12,990 | false | Lets break the question into simple parts:\n\n1. Lets think that we have no person and we have to find the minimum path between box and the target. Easy right? Simple BFS.\n\n2. If you know how to solve the first part, what I actually do is modify first part with few constraints. \n\t* \tI just check whether the box ca... | 200 | 2 | ['Breadth-First Search', 'Python'] | 22 |
minimum-moves-to-move-a-box-to-their-target-location | A-star search | a-star-search-by-yorkshire-2bnc | Heuristic (an under-estimate of the remaining moves required) is the Manhattan distance between box and target.\nA state consist of box and person locations tog | yorkshire | NORMAL | 2019-11-17T04:01:39.968224+00:00 | 2019-11-17T04:28:13.952575+00:00 | 15,903 | false | Heuristic (an under-estimate of the remaining moves required) is the Manhattan distance between box and target.\nA state consist of box and person locations together.\n\nRepeatedly pop the state with the lowest heuristic + previous moves off the heap.\nAttempt to move the person in all 4 directions.\nIf any direction m... | 104 | 2 | [] | 23 |
minimum-moves-to-move-a-box-to-their-target-location | Java straightforward BFS solution | java-straightforward-bfs-solution-by-cod-3d6b | For me, this is a typical bfs question to find the minimum step, so the key point is to find out the state. For this problem, I choose the coordinates of box an | codejoker | NORMAL | 2019-11-17T10:53:27.726916+00:00 | 2019-11-22T07:14:41.730605+00:00 | 11,891 | false | For me, this is a typical bfs question to find the minimum step, so the key point is to find out the state. For this problem, I choose the coordinates of box and storekeeper as the state. Because the grid length is from 1 to 20, we can use one 32 bit integer to present all the coordinates.\nEvery step, move storekeeper... | 95 | 6 | [] | 20 |
minimum-moves-to-move-a-box-to-their-target-location | Java use 2 level BFS, beat 99% | java-use-2-level-bfs-beat-99-by-hobiter-nejs | It will be easy coming up with BFS. But some key point:\n1, you need to make sure Storekeeper:\na has room to push the box;\nb has a way to go to the room to pu | hobiter | NORMAL | 2020-06-28T05:53:19.973855+00:00 | 2020-06-28T05:53:40.245418+00:00 | 4,904 | false | It will be easy coming up with BFS. But some key point:\n1, you need to make sure Storekeeper:\na has room to push the box;\nb has a way to go to the room to push the box. \nTherefore you need another bfs to find if the path exist;\n\n2 Make sure to set box as a blocker during bfs;\n\n3, Visited boolean array is tricky... | 50 | 3 | [] | 11 |
minimum-moves-to-move-a-box-to-their-target-location | cpp two bfs solution, 8ms beat 100% | cpp-two-bfs-solution-8ms-beat-100-by-sgu-1c3b | typical bfs problem for shortest distance.\nThe person shall be able to move to the location behind the box to make a move.\nwe can use dfs/bfs to check if pers | sguo-lq | NORMAL | 2019-11-19T00:01:28.037145+00:00 | 2019-11-19T00:01:28.037199+00:00 | 3,866 | false | typical bfs problem for shortest distance.\nThe person shall be able to move to the location behind the box to make a move.\nwe can use dfs/bfs to check if person can move to desired location.\nhowever dfs will get TLE since dfs is one direction forward until failure, hence dfs will use more time in average.\n\ncheck i... | 38 | 1 | [] | 4 |
minimum-moves-to-move-a-box-to-their-target-location | Python Dijkstra Short | python-dijkstra-short-by-dylan20-0rjf | edit: added an explanation below\nedit2: fixed a bug found by StefanPochmann@\n\n\ndef minPushBox(self, grid: List[List[str]]) -> int:\n free = set((i, j) fo | dylan20 | NORMAL | 2019-11-17T15:38:37.842010+00:00 | 2019-12-01T19:45:41.835144+00:00 | 2,834 | false | edit: added an explanation below\nedit2: fixed a bug found by StefanPochmann@\n\n```\ndef minPushBox(self, grid: List[List[str]]) -> int:\n free = set((i, j) for i, row in enumerate(grid) for j, cell in enumerate(row) if cell != \'#\')\n target = next((i, j) for i, row in enumerate(grid) for j, cell in enumerate(... | 37 | 0 | [] | 10 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.