Java code | O(m*n) 🚀
Intuition\nThe problem involves finding a path from the top-left to the bottom-right of a grid while managing health points that decrease based on grid values.\
# Intuition\nThe problem involves finding a path from the top-left to the bottom-right of a grid while managing health points that decrease based on grid values.\n\n# Approach\nUse Breadth-First Search (BFS) to explore the grid from the starting point. Track health at each cell and only move to cells with positive health. Use a queue to manage the exploration and an array to keep track of maximum health at each cell.\n\n# Complexity\n- Time complexity: $$O(m \\times n)$$\n- Space complexity: $$O(m \\times n)$$\n\n# Code\n```java\nclass Solution {\n    public boolean findSafeWalk(List<List<Integer>> grid, int health) {\n        int m = grid.size();\n        int n = grid.get(0).size();\n        int[][] directions = { {0, 1}, {1, 0}, {0, -1}, {-1, 0} };\n        Queue<int[]> q = new LinkedList<>();\n        q.offer(new int[] {0, 0, health - grid.get(0).get(0)});\n        int[][] visited = new int[m][n];\n        for (int[] row : visited) {\n            Arrays.fill(row, -1);\n        }\n        visited[0][0] = health - grid.get(0).get(0);\n\n        while (!q.isEmpty()) {\n            int[] curr = q.poll();\n            int x = curr[0];\n            int y = curr[1];\n            int currHealth = curr[2];\n            if (x == m - 1 && y == n - 1 && currHealth > 0) {\n                return true;\n            }\n\n            for (int[] direction : directions) {\n                int newX = x + direction[0];\n                int newY = y + direction[1];\n                if (newX >= 0 && newY >= 0 && newX < m && newY < n) {\n                    int newHealth = currHealth - grid.get(newX).get(newY);\n                    if (newHealth > 0 && newHealth > visited[newX][newY]) {\n                        visited[newX][newY] = newHealth;\n                        q.offer(new int[] {newX, newY, newHealth});\n                    }\n                }\n            }\n        }\n        return false;\n    }\n}\n```\n\n# Found this helpful? Give it an upvote! \uD83D\uDC4D\uD83D\uDE0A\n
['Java']