Beats 100%🔥|| BFS🔥|| JAVA✅
Code\njava []\nclass Solution {\n    public boolean findSafeWalk(List<List<Integer>> grid, int health) {\n        Queue<Pair> q=new LinkedList<>();\n        int
# Code\n```java []\nclass Solution {\n    public boolean findSafeWalk(List<List<Integer>> grid, int health) {\n        Queue<Pair> q=new LinkedList<>();\n        int n=grid.size(),m=grid.get(0).size();\n        int[][] vis=new int[n][m];\n        for(int[] a:vis) Arrays.fill(a,Integer.MAX_VALUE);\n        vis[0][0]=grid.get(0).get(0);\n        int[][] dir={{0,1},{0,-1},{1,0},{-1,0}};\n        q.add(new Pair(0,0,0));\n        while(!q.isEmpty()){\n            Pair x=q.poll();\n            int h=x.val+grid.get(x.r).get(x.c),r=x.r,c=x.c;\n            if(r==n-1 && c==m-1 && h<health) return true;\n            for(int[] a:dir){\n                int nr=r+a[0],nc=c+a[1];\n                if(nr>=0 && nc>=0 && nr<n && nc<m){\n                    if(h<vis[nr][nc]){\n                        vis[nr][nc]=h;\n                        q.add(new Pair(vis[nr][nc],nr,nc));\n                    }\n                }\n            }\n        }\n        return false;\n    }\n}\nclass Pair{\n    int val,r,c;\n    Pair(int val,int r,int c){\n        this.val=val;\n        this.r=r;\n        this.c=c;\n    }\n}\n```
['Breadth-First Search', 'Java']