Java beat 100% DFS solution
Here, we just need to go in all the 8 directions and if we encounter the queen, add them to the\nanswer.\n\n\tclass Solution {\n\t\tpublic List> queensAttackthe
Here, we just need to go in all the 8 directions and if we encounter the queen, add them to the\nanswer.\n\n\tclass Solution {\n\t\tpublic List<List<Integer>> queensAttacktheKing(int[][] queens, int[] king) {\n        \n\t\t//List that will contain our answer\n        List<List<Integer>> ans = new ArrayList<>();\n        \n\t\t//All 8 direction\n        int[][] dir = {{-1,0},{-1,-1},{0,-1},{1,-1},{1,0},{1,1},{0,1},{-1,1}};\n        \n\t\t//Board that will help us in identifying the location of queen\n        boolean[][] board = new boolean[8][8];\n        \n\t\t//Identify the queens on board\n        for(int[] a : queens)\n            board[a[0]][a[1]] = true;\n        \n        //Go in every direction \n        for(int[] a : dir){\n            int[] temp = new int[]{king[0]+a[0],king[1]+a[1]};\n            dfs(ans,board,temp,a);\n        }\n        return ans;\n    }\n    \n    private void dfs(List<List<Integer>> ans, boolean[][] board, int[] curr, int[] dir){\n\t\t//Base checks\n        if(curr[0]<0 || curr[0]>=8)\n            return;\n        \n        if(curr[1]<0 || curr[1]>=8)\n            return;\n        \n\t\t//If we found a queen then no needs to go further\n        if(board[curr[0]][curr[1]]){\n            List<Integer> temp = new ArrayList<>();\n            temp.add(curr[0]);\n            temp.add(curr[1]);\n            ans.add(temp);\n            return;\n        }\n        \n        curr[0] += dir[0];\n        curr[1] += dir[1];\n        \n        dfs(ans,board,curr,dir);\n    }\n}
['Depth-First Search', 'Java']