TikTok interview question

Two graph problems, using bfs.