Simple Python Solution | Beats 75% | BFS | Priority Queue
Code


# Code
```python3 []
class Solution:
    def findSafeWalk(self, grid: List[List[int]], health: int) -> bool:
        m, n = len(grid), len(grid[0])
        if grid[0][0] == 1:
            health -= 1
        heap = []
        directions = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        visited = [[float('-inf')] * n for _ in range(m)]
        visited[0][0] = health
        heapq.heappush(heap, (-health, 0, 0))
        while heap:
            health, i, j = heapq.heappop(heap)
            health = -health
            if health < 1:
                return False
            if (i, j) == (m-1, n-1):
                return True
            for di, dj in directions:
                ni, nj = i+di, j+dj
                if 0 <= ni < m and 0 <= nj < n:
                    new_health = health - (1 if grid[ni][nj] == 1 else 0)
                    if new_health > visited[ni][nj]:
                        visited[ni][nj] = new_health
                        heapq.heappush(heap, (-new_health, ni, nj))
        return False

        
```
['Breadth-First Search', 'Graph', 'Heap (Priority Queue)', 'Shortest Path', 'Python3']