3
vector<vector<int>> queensAttacktheKing(vector<vector<int>> &queens, vector<int> &king) {4
vector<vector<int>> ans;5
vector<vector<int>> board(8, vector<int>(8, 0));7
for (auto queen : queens) board[queen[0]][queen[1]] = 1;9
for (int x = -1; x <= 1; x++) // Both loops are for checking in all the 8 possible directions11
for (int y = -1; y <= 1; y++) {12
if (x == 0 and y == 0) continue;13
int startx = king[0], starty = king[1];15
while (startx >= 0 and startx < 8 and starty >= 0 and starty < 8) {16
if (board[startx][starty] == 1) // If queen is found, append it to ans and break18
ans.push_back({startx, starty});22
starty += y; // Otherwise keep moving forward in earlier direction