Amazon interview question

Leetcode easy-medium