Amazon interview question

A leetcode easy level question.