Domanda di colloquio di TikTok

An easy DFS/BFS coding problem, have to write test cases myself