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.
attacks = 0
directions = [(1, 0),(-1, 0),(0, 1),(0, -1),(1, 1),(-1, 1),(1, -1), (-1, -1) ]
obstacles = set(map(tuple, obstacles))
for dr, dc in directions:
r, c = r_q, c_q
while True:
r += dr
c += dc
if not (1 <= r <= n and 1 <= c <= n):
break
if (r, c) in obstacles:
break
attacks += 1
return attacks
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 →
**simple python solution **
def queensAttack(n, k, r_q, c_q, obstacles):