Question DSA-REC-0015
HardWhat is the output of this code?
def solve(n, r=0, cols=set(), d1=set(), d2=set()):
if r == n:
return 1
c = 0
for col in range(n):
if col in cols or r - col in d1 or r + col in d2:
continue
c += solve(n, r + 1, cols | {col}, d1 | {r - col}, d2 | {r + col})
return c
print(solve(4))
- A.
2
- B.
0
- C.
Sign up free to see the answer and a step-by-step explanation.