Loop to iterate over the elements of the matrix
for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 0 ; j < M ; j ++ ) { if ( mat [ i ] [ j ] > k ) { let m = mat [ i ] [ j ] - k ; if ( s . includes ( m ) ) { return true ; } } else { let m = k - mat [ i ] [ j ] ; if ( s . includes ( m ) ) { return true ; } } s . push ( mat [ i ] [ j ] ) ; } } return false ; }