Queen's Attack II Discussions | Algorithms | HackerRank
  • + 0 comments

    My Python solution: ' def queensAttack(n, k, r_q, c_q, obstacles): directions = [(1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (1, -1), (-1, 1), (-1, -1)] total = 0 # obstacles = set(obstacles) obstacles = set(tuple(obs) for obs in obstacles) for dx, dy in directions: x, y = r_q, c_q while True: x += dx y += dy if not (1 <= x <= n): break if not (1 <= y <= n): break if (x, y) in obstacles: break total += 1 return total

    '