Amazon interview question

for first round two leetcodes