Goldman Sachs interview question

LC Graph Question (No. Of Connected Islands)