Goldman Sachs interview question

Medium tasks from LeetCode -- DP and graph