You are viewing a single comment's thread. Return to all comments →
JS/Javascript solution:-
function queensAttack(n, k, r_q, c_q, obstacles) { let canQueenGo = 0; const obs = new Set(); obstacles.forEach(v => obs.add(`${v[0]},${v[1]}`)); function doTheAttack(dirX,dirY) { let posX = r_q + dirX; let posY = c_q + dirY; while (posX <= n && posY <= n && posX > 0 && posY > 0) { if (obs.has(`${posX},${posY}`)) return; canQueenGo++; posX += dirX; posY += dirY; } } for (let directionX = -1; directionX <= 1; directionX++) { for (let directionY = -1; directionY <= 1; directionY++) { if (directionY === 0 && directionX === 0) { continue; } else { doTheAttack(directionX, directionY) } } } return canQueenGo; }
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 →
JS/Javascript solution:-