Pregunta de entrevista de Hudson River Trading

Solve abstract math problem using Python