Goldman Sachs interview question

DSA question on graphs and trees