Dynamic Programming Pattern Leetcode Python