2D array memo for stopping solving same problem again
let memo = new Array ( M ) ; for ( let i = 0 ; i < M ; i ++ ) { memo [ i ] = new Array ( M ) ; for ( let j = 0 ; j < M ; j ++ ) { memo [ i ] [ j ] = 0 ; } }