Amazon Interview Question

Two leetcode problems of medium difficulty I would say.