Dijkstra
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# 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
```java []
class Solution {
    public boolean findSafeWalk(List<List<Integer>> grid, int health) {
        int[][] distance = new int[grid.size()][grid.get(0).size()];

        for (int[] d : distance) {
            Arrays.fill(d, Integer.MAX_VALUE);
        }

        distance[0][0] = grid.get(0).get(0);

        dijkstra(grid.size(), grid.get(0).size(), distance, grid);

        return distance[grid.size() - 1][grid.get(0).size() - 1] <= health - 1;

        
    }

    public void dijkstra(int n, int m, int[][] distance, List<List<Integer>> grid) {

        PriorityQueue<int[]> q = new PriorityQueue<>((a, b) -> distance[a[0]][a[1]] - distance[b[0]][b[1]]);
        HashSet<List<Integer>> visited = new HashSet<>();

        q.add(new int[]{0, 0});

        while(!q.isEmpty()) {
            int[] p = q.poll();
            if(visited.contains(List.of(p[0], p[1]))) {
                continue;
            }

            visited.add(List.of(p[0], p[1]));

            for(int[] neighbor : findNeighbors(n, m, p)) {
                if (visited.contains(List.of(neighbor[0], neighbor[1]))) {
                    continue;
                }

                distance[neighbor[0]][neighbor[1]] = Math.min(distance[neighbor[0]][neighbor[1]], distance[p[0]][p[1]] + grid.get(neighbor[0]).get(neighbor[1]));
                q.add(neighbor);
            }
        }

    }

    public ArrayList<int[]> findNeighbors(int n, int m, int[] curr) {
        ArrayList<int[]> res = new ArrayList<>();
        int[][] directions = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

        for (int[] direction : directions) {
            int[] ne = {curr[0] + direction[0], curr[1] + direction[1]};

            if (ne[0] >= 0 && ne[0] < n && ne[1] >= 0 && ne[1] < m) {
                res.add(ne);
            }
        }
        return res;
    }
}
```
['Java']