✅ Java | Easy | BFS | Without DP
Simple BFS Technique\n\nclass Pair{\n    int x;\n    int y;\n    int steps;\n    Pair(int x,int y,int steps){\n        this.x=x;\n        this.y=y;\n        thi
**Simple BFS Technique**\n```\nclass Pair{\n    int x;\n    int y;\n    int steps;\n    Pair(int x,int y,int steps){\n        this.x=x;\n        this.y=y;\n        this.steps=steps;\n    }\n}\nclass Solution {\n    public int maxMoves(int[][] grid) {\n        int max=0;\n        for(int i=0;i<grid.length;i++){\n            int cnt=bfs(grid,i);\n            max=Math.max(max,cnt);\n        }\n        return max;\n    }\n    public int bfs(int[][] grid,int row){\n        Queue<Pair> qu=new LinkedList<>();\n        qu.add(new Pair(row,0,0));\n        boolean[][] vis=new boolean[grid.length][grid[0].length];\n        vis[row][0]=true;\n        int steps=0;\n        while(!qu.isEmpty()){\n            Pair p=qu.poll();\n            int x=p.x;\n            int y=p.y;\n            steps=p.steps;\n            int diri[]={-1,0,1};\n            int dirj[]={1,1,1};\n            for(int i=0;i<3;i++){\n                int curri=x+diri[i];\n                int currj=y+dirj[i];\n                if(curri>=0 && curri<grid.length && currj>=0 && currj<grid[0].length && !vis[curri][currj] && grid[curri][currj]>grid[x][y]){\n                    qu.add(new Pair(curri,currj,steps+1));\n                    vis[curri][currj]=true;\n                }\n            }\n        }\n        return steps;\n    }\n}\n```\n![image](https://assets.leetcode.com/users/images/129511c2-6ae3-44de-b557-03c631a73683_1684046372.291239.jpeg)\n
['Breadth-First Search', 'Java']