Amazon interview question

solve a leetcode eays problem