Code for class Memoization and the correct code