Queen's Attack II Discussions | Algorithms | HackerRank
We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This is the explanation given in my solution on Github:
/*We can keep a running closest obstaclefor each direction(8 total) with relation toour queen as we read in all the obstacles from stdinthen we can just calculate the squares coveredusing the distance between two points for eachof 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
Cookie support is required to access HackerRank
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 →
This is the explanation given in my solution on Github:
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