Queen's Attack II Discussions | Algorithms | HackerRank
  • + 0 comments
    def queensAttack(n, k, r_q, c_q, obstacles):
        print(obstacles)
        obstacles = set(tuple(map(tuple, obstacles)))
        directions = [(1,-1), (1,0), (1,1), (0,-1), (0,1), (-1,-1), (-1,0), (-1,1)]
        print(dir)
        
        ans = 0
        for dy, dx in directions:
            y, x = r_q, c_q
            while True:
                y += dy
                x += dx
                if not (1 <= y <= n):
                    break
                if not (1 <= x <= n):
                    break
                if (y,x) in obstacles:
                    break
                ans +=1
        
        return ans