C++ | O1 BFS | Deque
Code

# Code
```cpp []
class Solution {
public:
    int dx[4]={0,1,0,-1};
    int dy[4]={1,0,-1,0};
    bool valid(int x,int y, int m, int n)
    {
        return x>=0 && x<m && y>=0 && y<n;
    }
    bool findSafeWalk(vector<vector<int>>& grid, int health) 
    {
        int m=grid.size(), n=grid[0].size();
        vector<vector<int>>dist(m,vector<int>(n,INT_MAX));
        dist[0][0]=grid[0][0];
        deque<vector<int>>dq;
        dq.push_back({0,0});
        while(!dq.empty())
        {
            int i=dq.front()[0],j=dq.front()[1];
            dq.pop_front();
            if(i==m-1 && j==n-1)
               return dist[i][j]<health;
            for(int k=0;k<4;k++)
            {
                int x=i+dx[k],y=j+dy[k];
                if(valid(x,y,m,n) && dist[x][y]>dist[i][j]+grid[x][y])
                {
                    dist[x][y]=dist[i][j]+grid[x][y];
                    if(grid[x][y])
                       dq.push_back({x,y});
                    else
                       dq.push_front({x,y});   
                }
            }   
        }
        return true;
    }
};
```
['C++']