TikTok interview question

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