Goldman Sachs Interview Question

leet code medium graph question