C++ | Easy Understanding | Clean and Concise | Well Explained
\nclass Solution {\npublic:\n    vector<vector<int>> queensAttacktheKing(vector<vector<int>>& queens, vector<int>& king) {\n        vector<vector<int>> ans;\n  
```\nclass Solution {\npublic:\n    vector<vector<int>> queensAttacktheKing(vector<vector<int>>& queens, vector<int>& king) {\n        vector<vector<int>> ans;\n        int queenPosition[8][8] = {}; // here we intialise all elements to 0, if we do not initialise then array is filled with garbage value\n        for(auto& q : queens) queenPosition[q[0]][q[1]] = 1;  // storing the queen positions, where the queen are present are filled with 1 and all others are 0\n        \n        vector<int> dirs = {-1, 0, 1}; // by using this vector we easily trace 8 directions without writing enough line of code\n        for(int dx : dirs) {\n            for(int dy : dirs) {\n                if(dx == 0 && dy == 0) continue;\n                int x = king[0], y = king[1];\n                while(x + dx >= 0 && x + dx < 8 && y + dy >= 0 && y + dy < 8) {\n                    x += dx, y += dy;\n                    if(queenPosition[x][y]) {\n                        ans.push_back({x, y});  // if garbage value is present then for every (row, column), if condition is true and our answer will contain extra or different (row, column)\n                        break;\n                    }\n                }\n            }\n        }\n        \n        return ans;\n    }\n};\n\n\n```
['Array', 'C', 'Matrix', 'Simulation']