Minimize the maximum minimum difference after one removal from array | Function to return the minimum required difference ; Sort the given array ; When minimum element is removed ; When maximum element is removed ; Return the minimum of diff1 and diff2 ; Driver Code
< ? php function findMinDifference ( $ arr , $ n ) { sort ( $ arr , 0 ) ; $ diff1 = $ arr [ $ n - 1 ] - $ arr [ 1 ] ; $ diff2 = $ arr [ $ n - 2 ] - $ arr [ 0 ] ; return min ( $ diff1 , $ diff2 ) ; } $ arr = array ( 1 , 2 , 4 , 3 , 4 ) ; $ n = sizeof ( $ arr ) ; echo findMinDifference ( $ arr , $ n ) ;