[Java] Check 8 steps, general approach, helpful in different questions
\nclass Solution {\n    int[][] directions = new int[][]{{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};\n    \n    public List<List<Integer>> queensAtt
```\nclass Solution {\n    int[][] directions = new int[][]{{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};\n    \n    public List<List<Integer>> queensAttacktheKing(int[][] queens, int[] king) {\n        List<List<Integer>> result = new ArrayList<>();\n        boolean[][] seen = new boolean[8][8];\n        for( int[] queen : queens ) seen[queen[0]][queen[1]] = true;        \n        dfs(result, seen, king);\n        return result;\n    }\n    \n    public void dfs(List<List<Integer>> list,boolean[][] seen, int[] king ){        \n        for(int[] dir : directions){\n            for(int i = king[0], j = king[1] ; i >= 0 && i < 8 && j >= 0 && j <8 ; i = i+dir[0], j = j+dir[1] ){\n                if( seen[i][j]){\n                    list.add(Arrays.asList(i,j));\n                    break;\n                }\n            }\n        }\n    }\n}\n```\n\n\nSame approach can be applied to https://leetcode.com/problems/available-captures-for-rook/\n```\nclass Solution {    \n    public int numRookCaptures(char[][] board) {\n       for( int i = 0; i < 8; i++){\n           for(int j = 0 ; j < 8;j++){\n               if(board[i][j] == \'R\'){\n                   return dfs(board,i,j);\n               }\n           }\n        }\n        return -1;\n    }\n    \n    public int dfs(char[][] board, int row,int column){\n        int res = 0;\n        int[][] directions = {{1,0}, {-1,0}, {0,1},{0,-1}};\n        \n        for( int[] dir : directions ){\n            for( int i = row, j = column; i>= 0 && i < 8  && j >=0 && j < 8; i = i+dir[0], j = j+dir[1]){\n                if( board[i][j] == \'p\'){\n                    res++;\n                    break;\n                }\n                else if( board[i][j] == \'B\'){\n                    break;\n                }\n            }\n        }\n        return res;\n    }\n}\n```
[]