Applied Intuition interview question

Leetcode hard (graph traversal question)