Amazon interview question

Two leetcode problems (easy to medium) difficulty