Google Interview Question

Solve DFS LeetCode question (middle)