Pregunta de entrevista de TikTok

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