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

    This is the explanation given in my solution on Github:

    /*
    We can keep a running closest obstacle
    for each direction(8 total) with relation to
    our queen as we read in all the obstacles from stdin
    then we can just calculate the squares covered
    using the distance between two points for each
    of the closest obstacles.
    */
    

    For determining whether the next obstacle is the closest to the queen for a given direction, you will want to check its' x and y to check what its' relationship with the queen is, then you can compare it to the closest obstacle you have so far in that direction and if this one is closer you replace it. Then once you have done this same process for every input, you will just calculate the distance from the queen to each of the obstacles and sum the values you get.

    If you are looking for a code example of how I accomplished this, checkout the solution on the HackerRank solution Github

    If the link doesn't work, remove the hacker rank redirect from the url