0/1 BFS | No heap or Dijkstra
javascript []\n/**\n * @param {number[][]} grid\n * @param {number} H - Initial health\n * @return {boolean} - Returns true if there\'s a safe path, otherwise f
```javascript []\n/**\n * @param {number[][]} grid\n * @param {number} H - Initial health\n * @return {boolean} - Returns true if there\'s a safe path, otherwise false\n */\nconst findSafeWalk = (grid, H) => {\n  const rows = grid.length;\n  const cols = grid[0].length;\n  const directions = [[0, 1], [1, 0], [0, -1], [-1, 0]];\n\n  // Health remaining at each point, initialize with negative infinity\n  const health = Array.from({ length: rows }, () => Array(cols).fill(-Infinity));\n\n  // Initialize deque for BFS\n  const queue = new Deque([[0, 0]]);\n\n  // Starting position (0, 0) with initial health\n  health[0][0] = H - grid[0][0];\n\n  while (!queue.isEmpty()) {\n    const [x, y] = queue.popFront();\n\n    for (const [dx, dy] of directions) {\n      const nx = x + dx;\n      const ny = y + dy;\n\n      // Check if the new position is within the grid bounds\n      if (nx >= 0 && nx < rows && ny >= 0 && ny < cols) {\n        const newHealth = health[x][y] - grid[nx][ny];\n\n        // Update health only if new health is better\n        if (newHealth > health[nx][ny]) {\n          health[nx][ny] = newHealth;\n\n          // Push to the front or back based on the grid value (0 or positive)\n          if (grid[nx][ny] === 0) {\n            queue.pushFront([nx, ny]); // Higher priority (zero-cost cells)\n          } else {\n            queue.pushBack([nx, ny]); // Lower priority (positive-cost cells)\n          }\n        }\n      }\n    }\n  }\n\n  // Return true if the health at the bottom-right corner is positive\n  return health[rows - 1][cols - 1] > 0;\n};\n```
['Array', 'Breadth-First Search', 'Graph', 'Matrix', 'Shortest Path', 'JavaScript']