Pergunta de entrevista da empresa Morgan Stanley

One puzzle to solve. Was relatively easy.