Pergunta de entrevista da empresa X

Leetcode question with minor change. Apply DFS/BFS to traverse a matrix. Follow-up question is another leetcode question that requires knowledge of prefix tree.