text: Largest gap in an array | A C # program to find largest gap between two elements in an array . ; function to solve the given problem ; Driver Code
code: using System ; class GFG { static int solve ( int [ ] a , int n ) { int max1 = int . MinValue ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( Math . Abs ( a [ i ] - a [ j ] ) > max1 ) { max1 = Math . Abs ( a [ i ] - a [ j ] ) ; } } } return max1 ; } static public void Main ( ) { int [ ] arr = { - 1 , 2 , 3 , - 4 , - 10 , 22 } ; int size = arr . Length ; Console . WriteLine ( " Largest ▁ gap ▁ is ▁ : ▁ " + solve ( arr , size ) ) ; } }