Java Solution | With Explanation
\n```\nclass Solution {\n    public List> queensAttacktheKing(int[][] queens, int[] king) {\n        List> result = new ArrayList<>();\n        Set set = new Ha
\n```\nclass Solution {\n    public List<List<Integer>> queensAttacktheKing(int[][] queens, int[] king) {\n        List<List<Integer>> result = new ArrayList<>();\n        Set<String> set = new HashSet<>();\n\t\t//putting queens coordinates into hash as a string\n        for (int i = 0; i < queens.length; i++) {\n            set.add(queens[i][0] + "" + queens[i][1]);\n        }\n        //up, up/right, right,  down/right, down, left/down, left, up/left\n        int[][] directions = new int[][]{{-1,0}, {-1,1}, {0,1}, {1,1}, {1,0}, {1,-1}, {0,-1}, {-1,-1}};\n\t\t//going on each direction and when meet first queen, then add to result and break\n\t\t//moving towards that direction\n        for (int i = 0; i < directions.length; i++) {\n            int y = king[0], x = king[1];\n            y += directions[i][0];\n            x += directions[i][1];\n            while (cellExists(y, x, 8, 8)) {\n                if (set.contains(y + "" + x)) {\n                    List<Integer> list = new ArrayList<>();\n                    list.add(y);\n                    list.add(x);\n                    result.add(list);\n                    break;\n                }\n                y += directions[i][0];\n                x += directions[i][1];\n            }\n        }\n        return result;\n    }\n    \n    private boolean cellExists(int row, int col, int rows, int cols) {\n        return (row <= rows - 1 && row >= 0) && (col <= cols - 1 && col >= 0);\n    }\n}
[]