TikTok Interview Question

DFS/BFS Leetcode Problem, easy to code