Java short|simple|fully commented Code
Complexity\n\nTime : As the size of chessboard is limited.\n\nFor the chessboard of N * N\nTime O(queens + 8N)\nSpace O(queens)\n\nJava Code :\n\n    public Lis
**Complexity**\n\nTime : As the size of chessboard is limited.\n\nFor the chessboard of N * N\nTime O(queens + 8N)\nSpace O(queens)\n\nJava Code :\n\n    public List<List<Integer>> queensAttacktheKing(int[][] queens, int[] king) {\n        \n        List<List<Integer>> res = new ArrayList<>();//for storing results\n\t\t\n\t\t//direction array for checking in all 8 directions\n        int[][] dir = {{0,1},{0,-1},{1,0},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}};\n        \n\t\t//creating hashset of queens sitting position for checking whether Queen is present at any particular position or not\n        HashSet<Integer> setofQueens= new HashSet<>();\n         for(int i=0;i<queens.length;i++){\n                int r=queens[i][0];\n                int c=queens[i][1];\n\t\t\t\t// addrowsandcolumns by making it a 2 digitnumber MSB is for rows and LSB is for columns for eg [1,0] = 10 \n                setofQueens.add(r*10+c);     \n         }\n        \n        //Algo Step 1 : Search For Attacking Queen from King\'s sitting position in all 8 possible chess baord directions \n\t    //Algo Step 2 : Validate Queens Presence in Hashset & Store the nearest QueensAttacking as List \n        int radius = 8;\n        int r=king[0];\n        int c=king[1];\n        \n        for(int d = 0; d < dir.length; d++){\n            \n            for(int rad = 1; rad < radius; rad++){\n                int rr = r + (rad * dir[d][0]);\n                int cc = c + (rad * dir[d][1]);\n\n                if(rr >= 0 && rr < radius && cc >= 0 && cc < radius) { // for moving only in valid positions in the board\n                    if(setofQueens.contains((rr*10+cc)))\n                    {\n                          res.add(Arrays.asList(rr,cc));// adding the nearest attacking queen row and columns as list to rest ArrayList\n                          break;// breaking after finding just nearest queen\n                    }   \n                }   \n            }\n        }\n        \n         return res;   \n        }
[]