Djiskira
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
```python3 []
class Solution:
    def findSafeWalk(self, grid: List[List[int]], health: int) -> bool:
        '''
        Approach: Keep track of what cells you visited for each path you are trying to go. 
        If I reach a cell with a life that is less than a life that I reached there with, then there is no need to continue on that cell. Becuase if the previous path failed, then this one will fail too. 

        Kepp track of the maximum health you reached to a certain cell with. 

        I will visit and relax a node if I can reach that node with greater health. If the health is the same, then there is another path that already visited this cell, that I checked. 
        
        '''


        def verify_cell(cell):
            row, col = cell
            return row >= 0 and row < len(grid) and col >= 0 and col < len(grid[0])


        healths = [[0] * len(grid[0]) for _ in range(len(grid))]
        healths[0][0] = health
        heap = [(-health + grid[0][0], (0, 0))]


        while heap:
            health, cell = heapq.heappop(heap)
            for index in range(2):
                for appending in (1, -1):
                    new_cell = list(cell)
                    new_cell[index] += appending
                    if verify_cell(new_cell):
                        row, col = new_cell
                        new_health = abs(health) - grid[row][col]
                        if new_health > healths[row][col] and new_health > 0:
                            healths[row][col] = new_health
                            heapq.heappush(heap, (-new_health, (row, col)))
        
        return healths[len(grid) - 1][len(grid[0]) - 1] > 0
```
['Python3']