Initialize a 2 - D array for memoization
int [ , ] dp = new int [ N , M ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { dp [ i , j ] = - 1 ; } } return maxProductUtil ( N - 1 , M - 1 , A , B , dp ) ; }