My function with the parameter n=1 returns the correct result - [[0]]. However, when I run the tests, this result is marked as an error. The same happens with tests 4 to 7. Could you please tell me what could be wrong with the output? Is there any way to find out what data the test expects to see in order to understand my mistake?
def dfs_n_queens(n):
if n < 0:
return []
result = []
stack = []
for j in range(n):
stack.append(j)
visited = []
def is_valid_location(index):
row = len(visited)
for i in range(len(visited)):
if index == visited[i]:
return False
diff = row - i
if visited[i] == index - diff or visited[i] == index + diff:
return False
return True
def find_children_down():
children = []
for index in range(n):
if is_valid_location(index):
children.append(index)
return children
while stack:
current = stack.pop()
if current not in visited:
visited.append(current)
if len(visited) != n:
children = find_children_down()
if children:
stack.extend(child for child in find_children_down())
else:
visited.pop()
else:
result.append(visited)
return result
print(f"result: {dfs_n_queens(1)}")