You are viewing a single comment's thread. Return to all comments →
Cries in no. 1 grid problem hater:
int queensAttack(int n, int k, int r_q, int c_q, vector<vector<int>> obstacles) { set<pair<int,int>> obs; for (auto &o : obstacles) { obs.insert({o[0], o[1]}); } vector<pair<int,int>> directions = { {1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1} }; int count = 0; for (auto [dr, dc] : directions) { int r = r_q + dr; int c = c_q + dc; while (r >= 1 && r <= n && c >= 1 && c <= n && !obs.count({r,c})) { count++; r += dr; c += dc; } } return count; }
Seems like cookies are disabled on this browser, please enable them to open this website
Queen's Attack II
You are viewing a single comment's thread. Return to all comments →
Cries in no. 1 grid problem hater: