Amazon interview question

Two leetcode questions (check description)