Rippling interview question

leetcode medium dfs and union find