Traverse in all 8 directions from the King
A queen can only attack the king if it\'s in the same row/column/diagonal of the king, and also no other queen should be in it\'s way. Hence we will traverse in
A queen can only attack the king if it\'s in the same row/column/diagonal of the king, and also no other queen should be in it\'s way. Hence we will traverse in all 8 directions from the king\'s coordinates and if we find a queen, then add it to the list and stop checking for that direction (only the first encountered queen in a particular direction can attack the king). There can be at most 8 queens that can attack the king.\n\n```\nclass Solution \n{\n    public List<List<Integer>> queensAttacktheKing(int[][] queens, int[] k) \n    {\n        List<List<Integer>> dangerousQueens = new ArrayList<>();\n        boolean[][] isQueen = new boolean[8][8];\n        for(int[] q: queens)\n            isQueen[q[0]][q[1]] = true;\n        int[] dx = {1, -1, 0, 0, 1, -1, 1, -1};\n        int[] dy = {0, 0, 1, -1, 1, 1, -1, -1};\n        for(int i=0; i<8; i++)\n        {\n            int x = k[0];\n            int y = k[1];\n            while(x >= 0 && x < 8 && y >= 0 && y < 8)\n            {\n                x += dx[i];\n                y += dy[i];\n                if(x < 0 || x >= 8 || y < 0 || y >= 8)\n                    break;\n                if(isQueen[x][y])\n                {\n                    List<Integer> q = new ArrayList<>();\n                    q.add(x);\n                    q.add(y);\n                    dangerousQueens.add(q);\n                    break;\n                }\n            }\n        }\n        return dangerousQueens;\n    }\n}\n```
['Java']