Lyft Interview Question

Dfs related coding problem from leetcode