Pregunta de entrevista de Affirm

a leetcode-style task with some runtime constraints