Add increments needed to make the 1 st k - 1 elements of this window equal to the kth element of the current window
opsNeeded += ( k - 1 ) * ( ar [ i ] - ar [ i - 1 ] ) ; ans = Math . min ( ans , opsNeeded ) ; } return ans ; }