Heap, Maintain Maximum Health
Intuition\nthere is 4^(m*n) possibility if we using DFS, it will not accepted. The idea is, if we alredy visit the [y,x] coordinate and the current health is lo
# Intuition\nthere is 4^(m*n) possibility if we using DFS, it will not accepted. The idea is, if we alredy visit the [y,x] coordinate and the current health is lower than before (visited), just skip it. If not, consider it into traverse!\n\n# Approach\nPriority Queue, with health maintained \n\n# Complexity\n- Time complexity:\n$$O(m * n * log(m * n))$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(m * n)$$\n\n# Code\n```golang []\ntype Q struct {\n    y, x, h int\n}\n\ntype PQ []Q\nfunc (pq PQ) Less(i, j int) bool {return pq[i].h > pq[j].h} \nfunc (pq PQ) Swap(i, j int) {pq[i], pq[j] = pq[j], pq[i]} \nfunc (pq PQ) Len() int {return len(pq)}\n\nfunc (pq *PQ) Push(v interface{}) {\n    (*pq) = append((*pq), v.(Q))\n}\n\nfunc (pq *PQ) Pop() (v interface{}) {\n    v = (*pq)[pq.Len()-1]\n    (*pq) = (*pq)[:pq.Len()-1]\n    return v\n}\n\n\nfunc findSafeWalk(grid [][]int, health int) bool {\n    visit := make(map[[2]int]int)\n\n    var pq PQ\n    heap.Init(&pq)\n\n    heap.Push(&pq, Q{y: 0, x:0, h: health-grid[0][0]})\n\n    for len(pq) > 0 {\n        curr := heap.Pop(&pq).(Q)\n        if curr.y == len(grid)-1 && curr.x == len(grid[curr.y])-1 && curr.h > 0 {return true}\n        if curr.h <= visit[[2]int{curr.y, curr.x}] {\n            continue\n        }\n\n    \n        visit[[2]int{curr.y, curr.x}] = curr.h\n        y, x := curr.y, curr.x\n        next := [][2]int{\n            [2]int{0,-1},\n            [2]int{0,1},\n            [2]int{1,0},\n            [2]int{-1,0},\n        }\n        for _, n := range next {\n            if y+n[0] >= 0 && y+n[0] < len(grid) &&\n            x+n[1] >= 0 && x+n[1] < len(grid[y]) {\n                heap.Push(&pq, Q{y+n[0], x+n[1], curr.h-grid[y+n[0]][x+n[1]]})\n            }\n        }\n    }\n\n    return false\n}\n```
['Go']