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.
Queen's Attack II
Queen's Attack II
Sort by
recency
|
937 Discussions
|
Please Login in order to post a comment
My solution in Java.
The idea is count distances from queen on every cardinal point until:
a. An obstacle is found. b. Chessboard edge is found.
So response will be movesToNorth + movesToSouth + movesToEast+...
C++ O(n) time and space complexity (more at https://github.com/IhorVodko/Hackerrank_solutions , feel free to give a star :) )
python
def queensAttack(n, k, r_q, c_q, obstacles): final=0
I wrote a c# struct that saves the board state, and allows you to add an obstacle and modify the movable spaces based on the current state.