Amazon Interview Question

Solve this coding process in this time