Simple BFS | Standard BFS template | Beginner Friendly
Intuition\nWe have to reach at bottom of grid with health >= 1.\n\n# Approach\nFirst thing that came into my mind is BFS, same thought as finding the shortest p
# Intuition\nWe have to reach at bottom of grid with health >= 1.\n\n# Approach\nFirst thing that came into my mind is BFS, same thought as finding the shortest path.\n    - key point to note here is the visited array depends on health on three things. row, colm, & health.\n    -  Which means, reaching to cell (x, y) with health k is diffrent from reaching to same cell (x, y) with health k1.\n    - So will keep health also in our visited array. \n\n# Complexity\n- Time complexity:\nO(m * n * h);\n\n- Space complexity:\nO(m * n * h);\n\n# Code\n```csharp []\npublic class Solution \n{\n    int[] dx = {0, 1, 0, -1};\n    int[] dy = {1, 0, -1, 0,};\n    public bool FindSafeWalk(IList<IList<int>> grid, int health) \n    {\n        /*\n            cell state is depdendent on health\n            so visiting a cell with health = a, is diffrent from visiting a cell with health = b\n        */\n        int m = grid.Count;\n        int n = grid[0].Count;    \n\n        if (grid[0][0] == 1)\n            health -= 1;\n        if (health < 0)\n            return false;\n        //why health + 1 => we are counting health from 1\n        var visited = new bool[m , n, health + 1]; \n        var q = new Queue<(int r, int c, int h)>();\n        q.Enqueue((0, 0, health));\n        visited[0, 0, health] = true;\n\n        while (q.Count > 0) \n        {\n            (int r, int c, int h) = q.Dequeue();\n            if (r == m - 1 && c == n - 1)\n                return true;\n            for (int i = 0; i < 4; i++) \n            {\n                int x = r + dx[i];\n                int y = c + dy[i];\n                if (x >= 0 && y >= 0 && x < m && y < n)\n                {\n                    int h1 = h - grid[x][y];\n                    if (h1 >= 1 && !visited[x, y, h1]) \n                    {\n                        q.Enqueue((x, y, h1));\n                        visited[x, y, h1] = true;\n                    }\n                }\n            }\n        }\n        return false;\n    }\n}\n```
['C#']