text: Minimize the difference between the maximum and minimum values of the modified array | C ++ program to find the minimum difference . ; Function to return required minimum difference ; finding minimum and maximum values ; returning minimum possible difference ; Driver program ; function to return the answer
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; int minDiff ( int n , int x , int A [ ] ) { int mn = A [ 0 ] , mx = A [ 0 ] ; for ( int i = 0 ; i < n ; ++ i ) { mn = min ( mn , A [ i ] ) ; mx = max ( mx , A [ i ] ) ; } return max ( 0 , mx - mn - 2 * x ) ; } int main ( ) { int n = 3 , x = 3 ; int A [ ] = { 1 , 3 , 6 } ; cout << minDiff ( n , x , A ) ; return 0 ; }