Pergunta de entrevista da empresa Stellar Science

How would you code this specific algorithm?