Amazon interview question

First round was OA. Solve 2 medium leetcode questions