Nielsen interview question

DSA question from dynamic programming