Amazon interview question

1 coding challenge (leetcode easy)