Pregunta de entrevista de Walmart

Code the answer to this problem