Algorithm Design By Dynamic Programming Leetcode Question