Goldman Sachs Interview Question

two leetcode questions from two people