Bloomreach interview question

Dynamic programming question