Amazon Interview Question

Two leetcode problems (easy to medium) difficulty