Maximum difference after removing elements
let maxDiff = Number . MIN_VALUE ; for ( let j = 0 ; j < n - k - 1 ; j ++ ) { for ( let p = i ; p <= i + j ; p ++ ) { maxDiff = Math . max ( maxDiff , a [ p + 1 ] - a [ p ] ) ; } }