BFS + multi times visit track
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```csharp []\npublic class Solution {\n    public bool FindSafeWalk(IList<IList<int>> grid, int health) {\n        int rows = grid.Count, cols = grid[0].Count;\n        if (rows == 0 || cols == 0)\n            return true;\n        health -= grid[0][0];\n        if (health <= 0)\n            return false;\n\n        int[] dir = new int[] { 0, 1, 0, -1, 0 };\n        bool[,,] visited = new bool[rows, cols, health+1];\n\n        visited[0, 0, health] = true;\n        Queue<(int, int, int)> que = new();\n        que.Enqueue((0, 0, health));\n        while (que.Count > 0)\n        {\n            int qLen = que.Count;\n            for (int i = 0; i < qLen; i++)\n            {\n                (int x, int y, int curH) cur = que.Dequeue();\n                int r = cur.x, c = cur.y, restH = cur.curH;\n                if (r == rows - 1 && c == cols - 1)\n                    return true;\n\n                for (int p = 0; p < 4; p++)\n                {\n                    int newX = r + dir[p], newY = c + dir[p + 1];\n                    if (newX < 0 || newY < 0 || newX >= rows || newY >= cols)\n                        continue;\n\n                    int nextH = restH - grid[newX][newY];\n                    if (nextH >= 1)\n                    {\n                        if (newX == rows - 1 && newY == cols - 1)\n                            return true;\n\n                        if (!visited[newX, newY, nextH])\n                        { \n                            visited[newX, newY, nextH] = true;\n                            que.Enqueue((newX, newY, nextH));\n                        }\n                    }\n                }\n            }\n        }\n\n        return false;\n    }\n}\n```
['C#']