✅ Easy Solution Beats 100%
\uD83E\uDDE0 Intuition\nThe problem is similar to a pathfinding challenge where we need to find a safe path from the top-left corner to the bottom-right corner 
# \uD83E\uDDE0 Intuition\nThe problem is similar to a pathfinding challenge where we need to find a safe path from the top-left corner to the bottom-right corner of the grid. The grid contains obstacles (represented by 1s), which reduce the health of the traveler. The goal is to reach the destination with at least 1 health point remaining.\n\n# \uD83D\uDEE0\uFE0F Approach\n- We use a **priority queue** to perform a modified BFS/DFS where each state is represented by the remaining health and the current position `(row, col)`. \n- The traversal starts from the top-left corner, and we push the health value based on whether there is an obstacle at the starting point.\n- The traversal explores four possible directions: up, down, left, and right. \n- If the next cell is an obstacle, health is reduced, and if it\'s not, health remains the same.\n- The process continues until the bottom-right corner is reached with health \u2265 1.\n\n# \u23F3 Complexity\n\n- Time complexity:  \n  The time complexity is approximately **O(n \\* m)**, where `n` is the number of rows and `m` is the number of columns in the grid. This is because each cell is processed once, and the priority queue maintains the maximum health for each position.\n\n- Space complexity:  \n  The space complexity is **O(n \\* m)**, which accounts for the visited array and the priority queue storing the grid\'s cells.\n\n\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    bool findSafeWalk(vector<vector<int>>& grid, int health) {\n        int n=grid.size();\n        int m=grid[0].size();\n        priority_queue<pair<int,pair<int,int>>, vector<pair<int,pair<int,int>>>>qu;  //height : {row,col}\n        vector<vector<int>>vis(n,vector<int>(m,0));\n        if(grid[0][0]==1){\n            qu.push({health-1,{0,0}});\n        }\n        else{\n        qu.push({health,{0,0}});\n        }\n        vis[0][0]=1;\n        \n        while(!qu.empty()){\n            int val=qu.top().first;\n            int row=qu.top().second.first;\n            int col=qu.top().second.second;\n\n            if(row==n-1 && col==m-1){\n                if(val>=1){\n                    return true;\n                }\n            }\n\n            qu.pop();\n            int drow[4]={0,-1,0,1};\n            int dcol[4]={-1,0,1,0};\n            \n\n            for(int i=0;i<4;i++){\n                int n_row=row+drow[i];\n                int n_col=col+dcol[i];\n                if(n_row>=0 && n_row<n && n_col>=0 && n_col<m  &&  !vis[n_row][n_col] && grid[n_row][n_col]==0){\n                    vis[n_row][n_col]=1;\n                    qu.push({val,{n_row,n_col}});\n                }\n                else if (n_row>=0 && n_row<n && n_col>=0 && n_col<m  &&  !vis[n_row][n_col] && grid[n_row][n_col]!=0){\n                    vis[n_row][n_col]=1;\n                    qu.push({val-1,{n_row,n_col}});\n                }\n            }\n        }\n\n        return false;\n\n    }\n};\n```
['Depth-First Search', 'Breadth-First Search', 'Heap (Priority Queue)', 'C++']