Pregunta de entrevista de Accenture

Codiing question from codility and leat code