Amazon Interview Question

Two questions at Leetcode medium difficulty