Pergunta de entrevista da empresa Swiss Re

Can you solve the following coding problem?