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.
Java Solution
Here is my solution in Java that passes all cases in O(k) time with O(1) space.
Here is how it works:
We loop through the obstacles given and keep track of the closest one to our queen in each of the 8 directions, then we calculate the distance from our queen to each of the closest obstacles and return their sum.
Queen's Attack II
You are viewing a single comment's thread. Return to all comments →
Java Solution Here is my solution in Java that passes all cases in O(k) time with O(1) space.
Here is how it works: We loop through the obstacles given and keep track of the closest one to our queen in each of the 8 directions, then we calculate the distance from our queen to each of the closest obstacles and return their sum.