Queen's Attack II -- problem in hacker rank https://www.hackerrank.com/contests/devsprintapproach-mock-1/challenges/queens-attack-2/problem

Please tell where i am getting it wrong

#!/bin/python3

import math
import os
import random
import re
import sys

Complete the queensAttack function below.

def queensAttack(n, k, r_q, c_q, obstacles):

if name == ‘main’:
fptr = open(os.environ[‘OUTPUT_PATH’], ‘w’)

nk = input().split()

n = int(nk[0])

k = int(nk[1])

r_qC_q = input().split()

r_q = int(r_qC_q[0])

c_q = int(r_qC_q[1])

obstacles = []

for _ in range(k):
    obstacles.append(list(map(int, input().rstrip().split())))

result = queensAttack(n, k, r_q, c_q, obstacles)

fptr.write(str(result) + '\n')

fptr.close()

#!/bin/python3

import math
import os
import random
import re
import sys
import itertools

Complete the queensAttack function below.

def queensAttack(n, k, r_q, c_q, obstacles):

diag1_atack = 0
for i, j in zip(range(r_q, 1, -1), range(c_q, 1, -1)):
    temp = [i, j]
    if temp in obstacles:
        break
    diag1_atack = diag1_atack + 1

for i, j in zip(range(r_q+1, n+1), range(c_q+1, n+1)):
    temp = [i, j]
    if temp in obstacles:
        break
    diag1_atack = diag1_atack + 1
    

diag2_atack = 0
for i, j in zip(range(r_q-1, 0, -1), range(c_q+1, n+1)):
    temp = [i, j]
    if temp in obstacles:
        break
    diag2_atack = diag2_atack + 1

for i, j in zip(range(r_q+1, n+1), range(c_q-1, 0, -1)):
    temp = [i, j]
    if temp in obstacles:
        break
    diag2_atack = diag2_atack + 1
    
row_atack = 0
for i, j in zip(itertools.repeat(r_q), range(c_q+1, n+1)) :
    temp = [i, j]
    if temp in obstacles:
        break
    row_atack = row_atack + 1

for i, j in zip(itertools.repeat(r_q), range(c_q-1, 0, -1)):
    temp = [i, j]
    if temp in obstacles:
        break
    row_atack = row_atack + 1

col_atack = 0
for i, j in zip(range(r_q+1, n+1), itertools.repeat(c_q)) :
    temp = [i, j]
    if temp in obstacles:
        break
    col_atack = col_atack + 1

for i, j in zip(range(r_q-1, 0, -1), itertools.repeat(c_q)):
    temp = [i, j]
    if temp in obstacles:
        break
    col_atack = col_atack + 1
    
return (diag1_atack + diag2_atack + row_atack + col_atack)

if name == ‘main’:
fptr = open(os.environ[‘OUTPUT_PATH’], ‘w’)

nk = input().split()

n = int(nk[0])

k = int(nk[1])

r_qC_q = input().split()

r_q = int(r_qC_q[0])

c_q = int(r_qC_q[1])

obstacles = []

for _ in range(k):
    obstacles.append(list(map(int, input().rstrip().split())))

result = queensAttack(n, k, r_q, c_q, obstacles)

fptr.write(str(result) + '\n')

fptr.close()

Hi Som, the question is a little broad, it’s hard to tell what kind of help you need. Also, Mock assessments are meant to be strictly as a test, so we encourage you to try and solve it on your own.

Sure. Will try it again

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.

Closing this topic as your issue is resolved by the mentor. If it is still not resolved, Kindly un-mark the accepted solution or create a new topic and post this question as a reference link in the description of the new topic.