Remove exactly one element from the array such that max | C # implementation of the above approach ; function to calculate max - min ; Driver code
using System ; class GFG { static int max_min ( int [ ] a , int n ) { Array . Sort ( a ) ; return Math . Min ( a [ n - 2 ] - a [ 0 ] , a [ n - 1 ] - a [ 1 ] ) ; } public static void Main ( ) { int [ ] a = { 1 , 3 , 3 , 7 } ; int n = a . Length ; Console . WriteLine ( max_min ( a , n ) ) ; } }