Bug Report for https://neetcode.io/problems/islands-and-treasure
Not exactly a bug , rather a gap in the test cases. I couldn't find a place to contribute a test case so here I am .
The problem can be solved in multi-source bfs and we dont really need a visited array.
The below solution is accepted.
`class Solution {
public void islandsAndTreasure(int[][] grid) {
Queue<int[]> queue = new LinkedList<>();
int INF = 2147483647;
int m = grid.length, n = grid[0].length;
for(int i=0; i<m; ++i) {
for(int j=0; j<n; ++j) {
if(grid[i][j] == 0)
queue.offer(new int[]{i,j});
}
}
int[][] moves = new int[][]{{1,0},{-1,0},{0,1},{0,-1}};
int distance = 0;
while(!queue.isEmpty()) {
int size = queue.size();
while(size-- > 0) {
int[] cell = queue.poll();
int x = cell[0];
int y = cell[1];
if(x < 0 || x >= m || y < 0 || y >= n) {
continue;
}
if(grid[x][y] == -1) {
continue;
}
if(grid[x][y] < INF && grid[x][y] > 0) {
continue;
}
if(grid[x][y] == INF) {
grid[x][y] = distance;
}
for(int[] move : moves) {
queue.offer(new int[]{x+move[0], y+move[1]});
}
}
++distance;
}
}
}
`
but it throws TLE for this grid:
[[0,-1],[0,2147483647]]
Please add this test case in the judge.
Bug Report for https://neetcode.io/problems/islands-and-treasure
Not exactly a bug , rather a gap in the test cases. I couldn't find a place to contribute a test case so here I am .
The problem can be solved in multi-source bfs and we dont really need a visited array.
The below solution is accepted.
`class Solution {
}
`
but it throws TLE for this grid:
[[0,-1],[0,2147483647]]
Please add this test case in the judge.