Why is this n-queens recursive solution not working?
here is the code: from copy import deepcopy as dc class Solution: def solveNQueens(self, n: int) -> List[List[str]]: result = list() board =[["."]*n]*n def issafe(row, col, board): #check the left elements in row for i in range(col+1): if board[row][i]=="Q": return False row-=1 col-=1 row2 = row col2 = col #check down diagonal elements while row>=0 and col>=0: if board[row][col]=="Q": return False row-=1 col-=1 while col2>=0 and row2<n: if board[row2][col2]=="Q": return False row2+=1 col2-=1 return True def helper(col, board): if col==n: result.append(["".join(row) for row in board]) return for row in range(n): if issafe(row, col, dc(board)): board[row][col] = "Q" helper(col+1, dc(board)) board[row][col] = "." helper(0, dc(board)) return result