LinkedIn Interview Question

It is a basic Dynamic Programming question.