Up&Up (NY) interview question

Graph traversal problem leetcode basic