Beat 80% java solution ✅ || BFS
\n\nclass Pair{\n    int first;\n    int second;\n    int step;\n    Pair(int fst,int scnd,int step){\n        this.first=fst;\n        this.second=scnd;\n     
```\n\nclass Pair{\n    int first;\n    int second;\n    int step;\n    Pair(int fst,int scnd,int step){\n        this.first=fst;\n        this.second=scnd;\n        this.step=step;\n    }\n}\n\nclass Solution {\n    public int nearestExit(char[][] maze, int[] entrance) {\n        int n=maze.length;\n        int m=maze[0].length;\n\n        int x=entrance[0];\n        int y=entrance[1];\n\n        int delRow[]={1,-1,0,0};\n        int delCol[]={0,0,1,-1};\n        \n        int ans=0;\n        \n        Queue<Pair>q=new LinkedList<Pair>();\n        q.add(new Pair(x,y,0));\n        \n        while(!q.isEmpty()){\n            int row=q.peek().first;\n            int col=q.peek().second;\n            int step=q.peek().step;\n            maze[row][col]=\'+\';\n\n            \n            q.poll();\n\n            for(int i=0;i<4;i++){\n                int nrow=row+delRow[i];\n                int ncol=col+delCol[i];\n\n                if(nrow>=0 && nrow<n && ncol>=0 && ncol<m && maze[nrow][ncol]==\'.\'){\n                    maze[nrow][ncol]=\'+\';\n                    q.add(new Pair(nrow,ncol,step+1));\n                    \n                    \n                    if(nrow==0 || ncol==0 || nrow==n-1 || ncol==m-1){\n                        ans=step+1;\n                        return ans;\n                    }  \n                    \n                }\n\n            }\n            \n        }\n        return -1;\n\n\n    }\n\n}\n\n```\nThankyou:)
[]