3. What will be the output of the following TypeScript code snippet?
const board = [
['A','B','C','E'],
['S','F','C','S'],
['A','D','E','E']
];
function exist(board: string[][], word: string): boolean {
const rows = board.length;
const cols = board[0].length;
function backtrack(r: number, c: number, i: number): boolean {
if (i === word.length) return true;
if (r < 0 || c < 0 || r >= rows || c >= cols || board[r][c] !== word[i]) return false;
const temp = board[r][c];
board[r][c] = '#';
const found = backtrack(r+1, c, i+1) || backtrack(r-1, c, i+1) || backtrack(r, c+1, i+1) || backtrack(r, c-1, i+1);
board[r][c] = temp;
return found;
}
for (let r = 0; r < rows; r++) {
for (let c = 0; c < cols; c++) {
if (backtrack(r, c, 0)) return true;
}
}
return false;
}
console.log(exist(board, 'ABCCED'));