Amazon interview question

Two leetcode medium questions that used multiple data structres.