Amazon interview question

Two leetcode problems of medium difficulty I would say.