Basic Dynamic Programming Leetcode Problems Javascript