Question DSA-REC-0064
HardWhat is the output of this code?
def word_exists(board, w):
R, C = len(board), len(board[0])
def go(r, c, i):
if i == len(w): return True
if not (0 <= r < R and 0 <= c < C) or board[r][c] != w[i]: return False
ch, board[r][c] = board[r][c], "#"
ok = any(go(r + dr, c + dc, i + 1) for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)))
board[r][c] = ch
return ok
return any(go(r, c, 0) r (R) c (C))
B = [(), (), ()]
(word_exists(B, ), word_exists(B, ), word_exists(B, ))
- A.
True False False
- B.
True True False
- C.
Sign up free to see the answer and a step-by-step explanation.