Amazon interview question

Typical algorithmic questions. Intermediate level on leetcode