Bloomberg Interview Question

A DFS problem from leetcode