Java | BFS
\nclass Solution {\n    public boolean findSafeWalk(List<List<Integer>> grid, int health) {\n        int n = grid.size();\n        int m = grid.get(0).size();\n
```\nclass Solution {\n    public boolean findSafeWalk(List<List<Integer>> grid, int health) {\n        int n = grid.size();\n        int m = grid.get(0).size();\n        \n        int[] dr = new int[] {0, 0, 1, -1};\n        int[] dc = new int[] {1, -1, 0, 0};\n        \n        boolean[][][] visited = new boolean[n][m][health + 1];\n        Queue<int[]> bfs = new LinkedList<>();\n        \n        bfs.add(new int[]{0, 0, health - grid.get(0).get(0)});\n        visited[0][0][health - grid.get(0).get(0)] = true;\n        \n        while(!bfs.isEmpty()) {\n            int size = bfs.size();\n            while(size-- > 0) {\n                int[] currNode = bfs.poll();\n                int r = currNode[0];\n                int c = currNode[1];\n                int h = currNode[2];\n               \n                if(r == n-1 && c == m-1 && h > 0) {\n                    return true;\n                }\n                 \n                for(int k = 0; k < 4; k++) {\n                    int nr = r + dr[k];\n                    int nc = c + dc[k];\n                    if(isValidMove(nr, nc, n, m)) {\n                        int nh = h - grid.get(nr).get(nc);\n                        if(nh >= 0 && visited[nr][nc][nh] == false) {\n                            visited[nr][nc][nh] = true;\n                            bfs.add(new int[]{nr, nc, nh});\n                        }\n                    }\n                }\n            }\n        }\n        \n        return false;\n    }\n    \n    private boolean isValidMove(int r, int c, int n, int m) {\n        return r >= 0 && c >= 0 && r < n && c < m;\n    }\n}\n```
['Breadth-First Search', 'Java']