Amazon interview question

Leetcode easy type problem