added memoization sample code