Amazon interview question

Solve this coding process in this time