Goldman Sachs interview question

leet code medium graph question