Pergunta de entrevista da empresa Scalio

asked to solve a logic problem