Dynamic Programming Leetcode Problem