bfs with health score matrix | C++
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```cpp []\nclass Solution {\n    vector<int> moves_x{1, 0, -1, 0};\n    vector<int> moves_y{0, 1, 0, -1};\n    int m_rows, m_cols;\n    bool isSafe(int row, int col) \n        {return row >= 0 && col >=0 && row < m_rows && col < m_cols;}\npublic:\n    bool findSafeWalk(vector<vector<int>>& grid, int health);\n};\n\nbool Solution::findSafeWalk(vector<vector<int>>& grid, int health) {\n    m_rows = grid.size(), m_cols = grid[0].size();\n    vector<vector<int>> hcount(m_rows, vector<int>(m_cols, 0));\n    \n    queue<tuple<int, int, int>> hqueue; // health, row, col\n    hqueue.push({(health - grid[0][0]), 0, 0});\n    while (!hqueue.empty()) {\n        auto [h, i, j] = hqueue.front(); hqueue.pop();\n        if (i == m_rows - 1 && j == m_cols - 1)\n            return true;\n\n        for(int k = 0; k < 4; ++k) {\n            int x = i + moves_x[k], y = j + moves_y[k];\n            if (isSafe(x, y) && (hcount[x][y] < h - grid[x][y])) {\n                hcount[x][y] = h - grid[x][y];\n                hqueue.push({h - grid[x][y], x, y});\n            }\n        }\n    }\n    return false;\n}\n```
['C++']