Goldman Sachs Interview Question

DSA question on graphs and trees