Pregunta de entrevista de Amazon

Solve this coding process in this time