Amazon interview question

Leetcode easy. Seems i got lucky.