Goldman Sachs Interview Question

First question was of leetcode easy difficulty and second question was hard.