Deutsche Bank interview question

LC medium dynamic programming question