memoize optimization problem lecture example code added