Find the largest interval that contains exactly one of the given N integers . | C # implementation of the approach ; Function to return the maximum size of the required interval ; Insert the borders for array ; Sort the elements in ascending order ; To store the maximum size ; To store the range [ L , R ] such that only v [ i ] lies within the range ; Total integers in the range ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int maxSize ( List < int > v , int n ) { v . Add ( 0 ) ; v . Add ( 100001 ) ; n += 2 ; v . Sort ( ) ; int mx = 0 ; for ( int i = 1 ; i < n - 1 ; i ++ ) { int L = v [ i - 1 ] + 1 ; int R = v [ i + 1 ] - 1 ; int cnt = R - L + 1 ; mx = Math . Max ( mx , cnt ) ; } return mx ; } public static void Main ( String [ ] args ) { int [ ] arr = { 200 , 10 , 5 } ; List < int > v = new List < int > ( arr ) ; int n = v . Count ; Console . WriteLine ( maxSize ( v , n ) ) ; } }