Rippling Interview Question

leetcode medium dfs and union find