Affirm interview question

a leetcode-style task with some runtime constraints