Question DSA-REC-0046
MediumWhat is the output of this code?
def solve(n):
cols, d1, d2, cnt = set(), set(), set(), 0
def place(r):
nonlocal cnt
if r == n:
cnt += 1
return
for c in range(n):
if c in cols or r - c in d1 or r + c in d2:
continue
cols.add(c); d1.add(r - c); d2.add(r + c)
place(r + 1)
cols.remove(c); d1.remove(r - c); d2.remove(r + c)
place(0)
return cnt
print(solve(6))
- A.
2
- B.
4
- C.
Sign up free to see the answer and a step-by-step explanation.