Pregunta de entrevista de Stellar Science

How would you code this specific algorithm?