Loop to iterate over every possible cell of the matrix
for ( let i = 0 ; i < n ; i ++ ) { for ( let j = 0 ; j < m ; j ++ ) { let val = v [ i ] [ j ] - x * ( i + j ) ; for ( let k = 0 ; k < dp . length ; k ++ ) for ( let l = 0 ; l < dp [ k ] . length ; l ++ ) dp [ k ] [ l ] = - 1 ; val = min_operation ( 0 , 0 , val , x ) ; ans = Math . min ( ans , val ) ; } } return ans ; }