Amazon interview question

Leetcode medium or easy level difficulty.