Bloomberg interview question

LeetCode graph question: traverse using recursion and make sure you don’t get stuck in a loop.