TikTok interview question

Something related to graphs, leetcode hard