Xtremax interview question

dynamic programming