Pregunta de entrevista de Hudson River Trading

Classic coding question on python