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

    def queensAttack(n, k, r_q, c_q, obstacles):

    obs_map = {}
    for obs in obstacles:
        obs_map[obs[0], obs[1]] = 1
    
    deltas = [0, 1, -1]
    directions = []
    for i in deltas:
        for j in deltas:
            if i != 0 or j != 0:
                directions.append((i, j))
    
    
    count = 0
    for direction in directions:
        i, j = r_q + direction[0], c_q + direction[1]
        while obs_map.get((i, j)) is None and i > 0 and j > 0 and i < n+1 and j < n+1:
    
            count += 1
            i += direction[0]
            j += direction[1]
    return count