Pregunta de entrevista de Swiss Re

Can you solve the following coding problem?