Java faster than 99% - Using Modified Dijkstra Algo
\n# Code\njava []\nclass Solution {\n    public boolean findSafeWalk(List<List<Integer>> grid, int health) {\n\n        final int numberOfRows      = grid.size(
\n# Code\n```java []\nclass Solution {\n    public boolean findSafeWalk(List<List<Integer>> grid, int health) {\n\n        final int numberOfRows      = grid.size();\n        final int numberOfColumns   = grid.get(0).size();\n        final int[][] distMatrix = new int[numberOfRows][numberOfColumns];\n        for(int[] m : distMatrix) Arrays.fill(m, Integer.MAX_VALUE);\n\n        int currentHealth = health;\n        final Deque<List<Integer>> queue = new ArrayDeque<>();\n        final int weightRoot = grid.get(0).get(0);\n        queue.offer(List.of(0, 0));\n        distMatrix[0][0] = weightRoot;\n\n        while(!queue.isEmpty()) {\n            final List<Integer> node = queue.pollFirst();\n            final int rowParent     = node.get(0);\n            final int columnParent  = node.get(1);\n            final int distParent    = distMatrix[rowParent][columnParent];\n\n            if(rowParent == numberOfRows - 1 && columnParent == numberOfColumns - 1){\n                break;\n            }\n\n            for(final int[] direction : directions) {\n                int rowChild    = rowParent + direction[0];\n                int columnChild = columnParent + direction[1];\n\n                if(isValid(rowChild, numberOfRows, columnChild, numberOfColumns)) {\n\n                    final int distChild       = distMatrix[rowChild][columnChild];\n                    final int weightOfChild   = grid.get(rowChild).get(columnChild);\n\n                    if(distChild > weightOfChild + distParent) { \n                        distMatrix[rowChild][columnChild] = weightOfChild + distParent;\n\n                        if(weightOfChild == 1) \n                            queue.offerLast(List.of(rowChild, columnChild));\n                        else \n                            queue.offerFirst(List.of(rowChild,columnChild));\n                    }\n                }\n            }\n        }\n\n        return distMatrix[numberOfRows - 1][numberOfColumns - 1] < currentHealth;\n    }\n\n    final int[][] directions = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};\n    boolean isValid(final int row, final int rowFence, final int column, final int columnFence ){\n        return \n            row >= 0 && row < rowFence &&\n            column >= 0 && column < columnFence;\n    }\n\n\n\n\n\n}\n```
['Java']