Java | BFS
Run a bfs from king in all 8 directions. When a queen is detected stop bfs in that direction.\nInstead of a char array we can also use hashmap to check wether q
Run a bfs from king in all 8 directions. When a queen is detected stop bfs in that direction.\nInstead of a char array we can also use hashmap to check wether queen exist on that coordinate or not.\n```\nclass Solution {\n    public class Pair{\n        int x;\n        int y;\n        int dir;\n        public Pair(int x,int y,int dir){\n            this.x = x;\n            this.y = y;\n            this.dir = dir;\n        }\n    }\n    public int[] rdir = {-1,-1,0,1,1,1,0,-1};\n    public int[] cdir = {0,-1,-1,-1,0,1,1,1};\n    public List<List<Integer>> queensAttacktheKing(int[][] queens, int[] king) {\n        List<List<Integer>> ans = new ArrayList<>();\n        char[][] board = new char[8][8];\n        for(int i=0;i<8;i++){\n            for(int j=0;j<8;j++){\n                board[i][j] = \'.\';\n            }\n        }\n        for(int[] arr:queens){\n            int x = arr[0];\n            int y = arr[1];\n            board[x][y] = \'Q\';\n        }\n        Queue<Pair> qu = new ArrayDeque<>();\n        for(int i=0;i<8;i++){\n            int x = king[0];\n            int y = king[1];\n            qu.add(new Pair(x,y,i));\n        }\n        //bfs\n        while(qu.size()>0){\n            Pair rem = qu.remove();\n            //queen check\n            if(board[rem.x][rem.y] == \'Q\'){\n                List<Integer> subans = new ArrayList<>();\n                subans.add(rem.x);\n                subans.add(rem.y);\n                ans.add(subans);\n                continue;\n            }else{\n                int nx = rem.x + rdir[rem.dir];\n                int ny = rem.y + cdir[rem.dir];\n                if(nx>=0 && nx<8 && ny>=0 && ny<8){\n                    qu.add(new Pair(nx,ny,rem.dir));\n                }\n            }\n            \n        }\n        return ans;\n    }\n}\n```
['Breadth-First Search', 'Java']